【发布时间】:2018-03-06 02:49:16
【问题描述】:
以下是我在提交时将表单返回到 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)
<div class="form-group" style="height:270px;">
@Html.LabelFor(m => m.ImageFile, new { @class = "blue-text", @style =
"font-size:16px", @id = "" })
<input name="ImageFile" type="file" />
</div>
<div class="form-group">
<input type="submit" value="Submit" class="btn btn-primary" />
<input type="reset" value="Reset" class="btn" />
</div>
}
Jquery 函数无法序列化输入文件类型并将其发送到控制器,除非我将其更改为 json 。但是,如果我将其更改为 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;
}
【问题讨论】:
标签: javascript jquery json ajax asp.net-mvc