Question

Pls look at following code

                <select name="VideoType" id="VideoType" style="width:60px">
                <option value="All">All</option>
                <option value="Movie">Movie</option>
                <option value="Show">Show</option>
            </select>

<ul id="categories">
    @foreach (var genre in Model)
    {
        <li>@Html.ActionLink(genre.Title, 
            "Browse", "Store",
              new { Genre = genre.Title, VideoType =   }, null)
        </li>
    }
</ul>

As U can see in the actionlink, how do i ref the selected value of dropdownlist? For eg: Movie.

Thanks

Était-ce utile?

La solution

Like Darin said, you do it in javascript.

Add an id attribute to your anchor tag so that we can refer using that.

@Html.ActionLink(genre.Title, 
            "Browse", "Store",
              new { Genre = genre.Title, VideoType =   }, new { @id="link1"})

Then using javascript, change the link,

$(function(){

  $("#VideoType").change(function(){
      $("#link1").attr("href")="Store/"+$("#VideoType").val();
  });

}); 

Autres conseils

You can't do this because the ActionLink is generated on the server, whereas the selected value of the dropdown might change on the client. You will have to use javascript and subscribe to the onchange event of the dropdown and then modify the link of the anchor to include the selected value.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top