0
下面是當我在提交時將表單返回給jquery函數時的剃鬚刀代碼。輸入類型文件沒有被序列化在jQuery中ajax
@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;
}
非常感謝你的工作^ _ ^。 – Killua