當我點擊嵌套表單提交按鈕來上傳文件時,它會觸發客戶端驗證,並且我想阻止此操作。
我已經嘗試過兩種獨立的表單元素,它的工作原理。但我必須使用嵌套的表單元素,因爲這是要求(用於設計目的)。如何從嵌套表單上傳文件並阻止客戶端驗證MVC 4中的主表單?
以下是我的代碼。
查看代碼
@using (Html.BeginForm("AddEdit", "Leads", FormMethod.Post, new { @Id = "frmSaveLead", @class = "form-horizontal" }))
{
@Html.TextBoxFor(model => model.stTitle, new { @class = "m-wrap span12", @placeholder = "Lead Title", @maxlength = "100" })
@Html.ValidationMessageFor(model => model.stTitle)
@Html.TextAreaFor(model => model.stNote, new { @class = "m-wrap span12", @placeholder = "Lead Note" })
@Html.ValidationMessageFor(model => model.stNote)
@using (Html.BeginForm("FileUpload", "Leads", FormMethod.Post, new { @Id = "frmFileUpload", @enctype = "multipart/form-data" }))
{
<span class="btn green fileinput-button"><i class="icon-plus icon-white"> </i>
<span>Add file...</span>
<input type="file" name="files">
</span>
<button type="submit" class="btn blue start">
<i class="icon-upload icon-white"></i><span>Start upload</span>
</button>
}
<button type="submit" class="btn blue">
<i class="icon-ok"></i>Save
</button>
}
「我必須使用嵌套的表單元素,因爲這是要求」這是一個可怕的要求,看到如何根據HTML規範不允許嵌套表單。 –
@Marek,是的,我知道,這是不正確的方式。但是爲了設計目的。 – Chintan
你可以嘗試發送表單爲JSON使用jQuery – Nilesh