MVC中前台所得

时间:2021-07-29 00:43:47

前台页面时间格式修改:

@item.CreateTime.ToString("yyyy-MM-dd hh:mm:ss")

前台方法调用传参数:

<a href="#" title="编辑" onclick="openPrintMode ('edit','@item.KeyId');">编辑</a>

前台异步调controller中方法:

   var saveData = function () {
var postData = {
PrinterKeyId: $("#hid_printkeyId").val(),
SupplierKeyId: $("#hid_suppierkeyId").val(),
PrinterType:$("#printType").val(),
PrinterName: $("#printName").val(),
PrinterCode: $("#printCode").val()
};
console.log(postData);
$.ajax({
url: '/Supplier/AddPrinter',
type: 'POST',
data: postData,
success: function (res) {
if (res.flag) {
search();
}else {
alert(res.msg);
}
}
});
}

详见controller中方法:这其中传的就是一个实体,而实体中是有5个参数,分别为

PrinterKeyId、SupplierKeyId、PrinterType、PrinterName、PrinterCode。
        [HttpPost]
public JsonResult AddPrinter(SupplierPrinterAddRst request)
{
try
{
request.RequestVPiaoUserKeyId = UserHelper.CurrentUserId;
SupplierPrinterAddRsp response = WcfInvoke.Invoke(v => v.SupplierPrinterAdd(request));
if (response.Result.ResponseCode == )
{
return Json(new { flag = true, msg = "保存成功" });
}
else
{ //ResponseCode==1 编码或名称重复
return Json(new { flag=false,msg=response.Result.ErrorMessage});
} }
catch (Exception ex)
{
LogHelper.Error("保存打印机列表出现异常,执行SupplierController.AddPrinter=>SupplierPrinterAdd异常", ex);
return Json(new { flag = false, msg = ex.Message });
}
}