下面是我在提交时将表单返回到jquery函数时的剃刀代码.
@model Slider
@{
Layout = null;
}
@using (Html.BeginForm("AddOrEdit", "Slider", FormMethod.Post, new { enctype = "multipart/form-data" , onsubmit = "return SubmitForm(this)" }))
{
@Html.HiddenFor(m => m.Id)
@Html.LabelFor(m => m.ImageFile, new { @class = "blue-text", @style =
"font-size:16px", @id = "" })
}
除非我将其更改为json,否则Jquery函数无法序列化输入文件类型并将其发送到控制器.但如果我将其更改为json,我将无法获得验证
function SubmitForm(form) {
debugger;
$.validator.unobtrusive.parse(form);
debugger;
if ($(form).valid()) {
debugger;
$.ajax({
type: "POST",
url: form.action,
//"datatype": "json"
data: $(form).serialize(),
success: function (data) {
if (data.success) {
Popup.dialog('close');
dataTable.ajax.reload();
$.notify(data.message, {
globalPosition: "top center",
className: "success"
})
} else {
Popup.dialog('close');
$.notify(data.message, {
globalPosition: "top center",
className: "error"
})
}
}
});
}
return false;
}