asp.net MVC+EasyUI用 Form Post 提交数据失败 Control不能接到数据

handsome‘sboy 2018-06-20 01:15:58
本人初学MVC 和EasyUI,做个信息采集页面,用Form Post 提交,后台Controller 却获得不到Requet数据?
AddInfo.cshtml
<div id="dlgAdd" class="easyui-dialog" style="" closed="true" buttons="#dlgAdd-btns">
<form id="frm" method="post" action="@Url.Action("Save")" >
<table id="GridData" class="easyui-datagrid" style="width:1000px;height:300px" data-options=" ">
<thead>
<tr>
<th data-options="field:'id',width:30">编号</th>
<th data-options="field:'bigclass',width:100,editor: { type: 'combobox', options: { required: true, editable: false, data : [{ 'id': '1', 'text': '优盘' },{ 'id': '2', 'text': '移动硬盘' },{ 'id': '3', 'text': '其他设备' }],valuefield: 'value', textfield: 'text' } }">大类</th>
<th data-options="field:'devicename',width:100,haign:'center',align:'left', editor: { type: 'text', options: { required: true } }">设备名称</th>
<th data-options="field:'model',width:100,align:'left',editor: { type: 'text', options: { required: true } } ">规格型号</th>
<th data-options="field:'number',width:100,align:'right',editor: { type: 'text', options: { required: true } }">数量</th>
<th data-options="field:'numunit',width:100,align:'right', editor: { type: 'combobox', options: { required: true, editable: false, data : [{ 'id': '1', 'text': '个' },{ 'id': '2', 'text': '只' },{ 'id': '3', 'text': '盒' }], valuefield: 'value', textfield: 'text' } }">数量单位</th>
<th data-options="field:'useperson',width:100,align:'left',editor: { type: 'text', options: { required: false } }">直接使用人</th>
<th data-options="field:'remark',width:100,align:'left',editor:'text'">备注</th>
@*<th data-options="field:'applydate',width:100,align:'left',editor:'text'">申请日期</th>
<th data-options="field:'apply',width:100,align:'left',editor:'text'">申请人</th>
<th data-options="field:'depart',width:100,align:'left',editor:'text'">申请单位</th>*@
</tr>
</thead>
<tr>
<td>
<div id="dlgAdd-btns">
<a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-add" plain=true onclick="Save()">保存 </a>
<a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-redo" plain=true onclick="Cancel()">取消</a>
</div>
</td>
</tr>
</table>
</form>

</div>
<script type="text/javascript">

function Add() {
$('#dlgAdd').dialog('open').dialog('setTitle', '添加');
initTable();
}


function Save() {

$('#frm').form('submit', {
//$.ajax({
url: '/BasicLevelUnitManage/Save',
type: 'POST',
dataType: 'json',
data: $('#frm').serializeObject(),
//data: [{
// "bigclass": $("#frm combox[name=bigclass]").val(),
// "devicename": $("#frm input[name=devicename]").val(),
// "model": $("#frm input[name=model]").val(),
// "num": $("#frm input[name=num]").val(),
// "numunit": $("#frm input[name=numunit]").val(),
// "useperson": $("#frm input[name=useperson]").val(),
// "remark": $("#frm input[name=remark]").val()
//}],

onSubmit: function () {
//console.log(jsonuserinfo);
//alert(JSON.stringify(jsonuserinfo));
//return $(this).form('validate');
},
success: function (data) {
//var result = eval('(' + result + ')');
alert("success:" + data);

//if (result.errorMsg) {
// $.messager.show({
// title: 'Error',
// msg: result.errorMsg
// });

// $('#dg').datagrid('reload'); // reload the user data
//} else {
// $.messager.show({
// title: '创建成功',
// msg: result.okMsg
// });
// $('#dlgAdd').dialog('close'); // close the dialog
// $('#dg').datagrid('reload'); // reload the user data
//}
}
});
}
</script>

控制器方法
public class BasicLevelUnitManageController : Controller
{
[HttpPost]
public ActionResult Save()
{ if ((Request.Form["bigclass"] != null)&&(Request.Form["model"] != null))&&(Request.Form["devicename"] != null))

{
string bigclass = Request.Form["bigclass"].ToString();
string model = Request.Form["model"].ToString();
string devicename = Request.Form["devicename"].ToString();
}

return Content("OK :" + "-");

}
...全文
446 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
handsome‘sboy 2018-07-09
  • 打赏
  • 举报
回复
@all 请问 在新增完成后如何实现修改(在大表里只修改部分字段)?只要考虑 针对部分字段是不是需要另外建立ModelView?
江湖评谈 2018-06-26
  • 打赏
  • 举报
回复


js里面的save 方法完全是多余的 action 直接等于控制/Action数据就可以传到后台。
正怒月神 版主 2018-06-26
  • 打赏
  • 举报
回复
你console.log一下 $('#frm').serializeObject(),
看看出来的是什么数据格式。
你后台要的是Request.Form["bigclass"]和Request.Form["model"]
全栈极简 2018-06-26
  • 打赏
  • 举报
回复
你在控制器方法中设置断点,调试,看Request里面是否有你想要的值。
丰云 2018-06-20
  • 打赏
  • 举报
回复
代码看起来很混乱,不想看了 你自己页面断点追踪一下,看看提交方法是否正常执行了撒

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧