我有一个下拉
<%=Html.DropDownList("genre", Model.genres, "", new { @onchange = ChangeMovie()" })%>
JavaScript 看起来像(不完整)
function ChangeMovie() {
var genreSelection = container.find( '#genre' ).val();
$.ajax({
"url" : "/Movies/GetGenre" ,
"type" : "get" ,
"dataType" : "json" ,
"data" : { "selectedValue" : $( "#genre").val() },
"success" : function (data) {}
});
};
控制器代码
public ActionResult GetGenre(string genreName)
{
//Need to get the `genreName` from the JavaScript function above.. which is
// in turn coming from the selected value of the drop down in the beginning.
}
我想通过 js 函数将下拉列表的选定值传递给控制器代码中的操作结果。我需要帮助来处理 JavaScript 代码和 AJAX 调用代码,以便将正确的值传递给控制器。