如何加载在mvc3按钮单击部分视图
问题描述:
我有一个DDL,在其更改我加载部分视图_GetX。现在我正在使用它像这样如何加载在mvc3按钮单击部分视图
@Html.DropDownListFor(model => model.XId, Model.XList, "Select", new { GetUrl = Url.Action("GetX", "Route") })
我需要单击按钮加载此局部视图。我该怎么做呢?
答
假设你GetX
控制器动作已经返回局部视图:
$(function() {
$('#someButton').click(function() {
// get the DDL. It would be better to add an id to it
var ddl = $('#XId');
// get the url from the ddl
var url = ddl.attr('GetUrl');
// get the selected value of the ddl to send it to the action as well
var selectedValue = ddl.val();
// send an AJAX request to the controller action passing the currently
// selected value of the DDL and store the results into
// some content placeholder
$('#somePlaceholder').load(url, { value: selectedValue });
return false;
});
});
您希望在DDL改变加载的局部视图或点击一些其他的按钮时? –
当点击其他buton时 – TJK