Novice
Novice

Reputation: 558

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"); %>
</div> 
<%: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"); %>
</div> 

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

Upvotes: 0

Views: 2622

Answers (3)

JoshYates1980
JoshYates1980

Reputation: 3626

Razor will take AJAX this way also:

<div class="editorholder">
  @Html.DropDownListFor(model => model.Display_ID, new SelectList(Model._listAllDisplayViewModel.ListAllDisplayInfo, "DisplayID", "DisplayName"), "Select.....", new { @class = "form-control", @id = "DisplayID", @onchange = "DisplayInfo();" })
</div>




<div class="editor-field">
  <div id="DisplayView">
    @Html.Partial("_DisplayView", Model._displayViewModel)
  </div>
 </div>




function DisplayInfo() {
    $("#DisplayView").load('@(Url.Action("_DisplayView", "Display", null, Request.Url.Scheme))?id=' + $("#DisplayID").val());
};

Upvotes: 0

Marsh
Marsh

Reputation: 173

u have to use ajax function for this:

  $('youractionlinkid').click(function () {
          var id = $('#yourdropdownid').val();
         $.ajax({
             url: this.href,
             type: 'GET',
             data: { id:id },
             cache: false,
             success: function (result) {
                 //do some action here
             }
         });
         return false;
     });

Upvotes: 0

Rowan Freeman
Rowan Freeman

Reputation: 16348

You can pass values with Html.ActionLink using routeValues in the parameter.

For example:

// VB
@Html.ActionLink("Link Text", "MyAction", New With {.eventId = 1})

// C#
@Html.ActionLink("Link Text", "MyAction", new {eventId = 1})

Might produce the link:

http://localhost/MyAction?eventId=1

Upvotes: 2

Related Questions