Novice Novice - 4 years ago 362
Javascript Question

Passing values in Html.ActionLink

I am very new to MVC and have Novice's knowledge about MVC.

I am creating an MVC application, where I have this page which displays Events taking place in a particular time.
Now when I select the event from the drop-down list, I get the specific event's details. Now along with that specific event's description, I need to get the feedback people has entered for that specific event.

Here is my View :

<div><a href="<%:Url.Action("ManagementHome","Home")%>">Home </a>>> Events</div>
<br />
<%:Html.LabelFor(m => m.Event)%>
<%:Html.DropDownListFor(m => m.Event.SelectedValue, Model.Event.GetSelectList(), new { id = "EventDropDown"})%>
<br /><br />
<div id="result" style="color: Green; border: 1px null transparent; ">
<%Html.RenderPartial("~/Views/PartialViews/EventsPartial.ascx"); %>
<%:Ajax.ActionLink("view", "viewFeedback", "Home", new AjaxOptions { UpdateTargetId = "comments" }, new {eventid=Model.Event.SelectedValue})%>

<div id="comments" style="color: Green; border: 1px null transparent;">
<%Html.RenderPartial("~/Views/PartialViews/FeedbackPartial.ascx"); %>

Can anyone please suggest how do I pass that event's ID in its ActionLink?
Thanks in advance

Answer Source

u have to use ajax function for this:

  $('youractionlinkid').click(function () {
          var id = $('#yourdropdownid').val();
             url: this.href,
             type: 'GET',
             data: { id:id },
             cache: false,
             success: function (result) {
                 //do some action here
         return false;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download