我正在使用带有Razor View的MVC 4
。该视图有两个Dropdown
列表和一个Submit
按钮。
<form id="mutualTradeFormId" method="get" action="@Url.Action("Index")">
<div class="col-sm-2">
<select id="FundFamilyId" name="FundFamily" class="FundFamilyClass">
@foreach (var item in Model.MutualFundFamilies)
{
<option value="@item.Value">@item.Text </option>
}
</select>
</div>
<select id="FundId" name="Fund" class="FundClass">
@foreach (var item in Model.mutualFunds)
{
<option value="@item.Value">@item.Text</option>
}
</select>
<div class="col-sm-2">
<input type="button" id="btnPreview" value="Preview Order" />
</div>
</form>
要加载第二个DropdownList
,我使用AJAX
来电,这就是<form>
代码使用Get
代替Post
$(document).on("change", '#FundFamilyId', function (e) {
SubmitFormjs();
});
function SubmitFormjs() {
var form = $('#mutualTradeFormId');
$.ajax({
type: form.attr('method'),
url: form.attr('action'),
data: form.serialize(),
success: function (data) {
$('#fundListId').replaceWith(data);
},
error: function (xhr) {
alert("An error occured: " + xhr.status + " " + xhr.statusText);
}
});
};
CONTROLLER
public ActionResult Index( string FundFamily = "")
{
if (FundFamily.Length > 0)
{
_vmfund.lstMutualFunds = DalOrders.GetFundsByFamilyId(FundFamily);
}
....
return View(_vmfund);
}
表单标记包含method="get"
,以便填充第二个DropdownList
。对于按钮点击,我想做一个帖子,我不知道如何构建控制器来为DDL填充HttpGet
和点击按钮HttpPost