我有一个asp.net mvc应用程序,使用JQuery UI对话框。我正在尝试将表单数据提交给控制器操作方法。我确实点击了动作方法,但我的对象没有数据。你知道为什么吗?
来自Filter.cshtml
$("#selectUnits").dialog({
autoOpen: false,
title: 'Select Units',
width: 400,
modal: true,
minHeight: 200,
buttons: {
"Cancel": function () {
$(this).dialog("close");
},
"Submit": function () {
$.post('/Data/SetUnitNumbers', $("#frmSelectedUnits").submit(), function (data) {
alert('This worked');
});
}
} // END OF BUTTONS
}); //END OF DIALOG
来自Controler ......行动方法:
public void SetUnitNumbers(object data)
{
int a = 5;
}
来自SelectUnits.cshtml,表单'frmSelectedUnits'存在。基本上,它是一堆复选框值,我正在尝试将其发送回服务器:
<body>
<form id="frmSelectedUnits" action="/" >
<div id="unitNumberCheckboxes" style=" ">
<div>
@Html.CheckBox("SelectAllUnitNumbers", false)<label for="SelectAllUnitNumbers"><b>Select/Unselect All Units</b></label>
</div>
<div id="unitCheckboxes">
@foreach (var item in Model)
{
<div style="float:left">
@Html.CheckBox("UnitNumbers", false)<label for="UnitNumbers">@item.unit_number.ToString().PadLeft(3, '0') </label>
</div>
}
</div>
</div>
</form>
</body>
答案 0 :(得分:0)
$.post(url, data, success-callback-function);
其中数据为A map or string that is sent to the server with the request.
调用$("#frmSelectedUnits").submit()
可能无效。
尝试:
$.post('/Data/SetUnitNumbers', $("#frmSelectedUnits").serialize(), function (data) {
alert('This worked');
});