How to get the @htmlDropDownList selected value?
I have a @htmlDropDownList
as
@Html开发者_运维技巧.DropDownList("MyList", new SelectList(Model.List, "Id", "Movie"))
in a mvc3 view.
How can I capture the selected value of this drop down list using javascript and use it to change the contents of the view according to the selected item?
To get the value is simple:
$('#MyList').val()
For the second part of the question I need more info.
UPDATE
How would we use the value?
//get the url for the movie description , define id as 0, so it is easier to replace lateron.
var moviedescriptionUrl = '@Url.Action("details", "movies", new { id = 0})';
//get the movieid
var movieID = $('#MyList').val();
//update a div
$('#movie-description').load(moviedescriptionUrl.replace('0', movieID));
Assuming I have an "details" action that return a partial view.
精彩评论