我認爲這是不可能的,因爲我無法讓它工作,儘管我幾乎讀了所有資源。我有一個表格,實際上是一個局部視圖,裏面有三個不同的形式:MVC多種形式和不顯眼的驗證
<div id="divTypePage" style="display:none" class="admin">
@using (Html.BeginForm("Type", "Inventory", FormMethod.Post, new { id = "typeForm" }))
{
<h4>Item Type Maintenance</h4>
<table class="table_body">
<tr>
<td>
<b style="color:red">*</b>Find Item Type or Enter New Code:
</td>
<td>
<input id="types" style="text-transform:uppercase" class="typeModel" />
@Html.HiddenFor(x=>x.ItemTypeModel.ItemTypeCode, new {@id = "txtTypeCode"})
</td>
</tr>
<tr>
<td>
<b style="color:red">*</b>@Html.DisplayNameFor(x=>x.ItemTypeModel.ItemTypeDescription)
</td>
<td>
@Html.TextBoxFor(x => x.ItemTypeModel.ItemTypeDescription, new { @id = "txtDesc", style="text-transform:uppercase", @class="typeModel" })
@Html.ValidationMessageFor(x=>x.ItemTypeModel.ItemTypeDescription)
</td>
</tr>
<tr>
<td>
@Html.DisplayNameFor(x=>x.ItemTypeModel.ItemTypePriority)
</td>
<td>
@Html.TextBoxFor(x => x.ItemTypeModel.ItemTypePriority, new { @id = "txtPrior", @maxLength = "1", style = "width: 50px", @class="typeModel" })
@Html.ValidationMessageFor(x=>x.ItemTypeModel.ItemTypePriority)
</td>
</tr>
</table>
}
</div>
<div id="divRolePage" style="display:none" class="admin">
@using (Html.BeginForm("Role", "Inventory", FormMethod.Post, new { @id = "roleForm" }))
{
<h4>Role Maintenance</h4>
<table class="table_body">
<tr>
<td>
<b style="color:red">*</b>Find Role or Enter New:
</td>
<td>
<input id="roles" class="roleModel" style="text-transform:uppercase" />
@Html.HiddenFor(x=>x.RoleModel.Role, new { @id = "txtRole"})
</td>
</tr>
<tr>
<td>
<b style="color:red">*</b>@Html.DisplayNameFor(x=>x.RoleModel.Description)
</td>
<td>
@Html.TextBoxFor(x=>x.RoleModel.Description, new { @id = "txtRoleDesc", style = "text-transform:uppercase", @class = "roleModel"})
</td>
</tr>
<tr>
<td>
@Html.DisplayNameFor(x=>x.RoleModel.Admin)
</td>
<td>
@Html.CheckBoxFor(x=>x.RoleModel.Admin, new { @id = "chkAdmin"})
</td>
</tr>
<tr>
<td>
@Html.DisplayNameFor(x=>x.RoleModel.Trans)
</td>
<td>
@Html.CheckBoxFor(x=>x.RoleModel.Trans, new { @id = "chkTrans"})
</td>
</tr>
<tr>
<td>
@Html.DisplayNameFor(x=>x.RoleModel.Reports)
</td>
<td>
@Html.CheckBoxFor(x=>x.RoleModel.Reports, new { @id = "chkReports"})
</td>
</tr>
</table>
}
</div>
我打開每一個通過使用一個對話框,我不是要去表演。但它是這樣的:
function OpenAdminPage(page) {
var type = page;
switch (page) {
case "type":
$("#divTypePage").dialog("open");
ParseForm("#typeForm");
break;
case "user":
ClearValues();
$("#divUserPage").dialog("open");
ParseForm("#userForm");
break;
case "role":
ClearValues();
$("#divRolePage").dialog("open");
ParseForm("#roleForm");
break;
}
return false;
}
和函數是這樣的:
function ParseForm(selector) {
var form = $(selector)
.removeData("Validator")
.removeData("unobtrusiveValidation");
$.validator.unobtrusive.parse(form);
}
但是,只有一個表格會顯示錯誤,另外兩個是給我這個:
0x800a03f6 - JavaScript runtime error: Invalid character
這在jQuery.parseJSON函數中的jquery-1.11.2中。我只是做了這個錯誤還是不可能這樣做?
你可以打破更多的形式,看看它是否仍然發生?試圖將它們移出部分視圖進行故障排除?把他們放在那裏有自己的部分意見? – jackncoke
如果使用'body'作爲選擇器(僅用於調試目的)會怎麼樣。它會發現並綁定到其他形式嗎? _unobtrusive.parse()_將查找屬性爲「data-val = true」的表單元素,這些表單元素是否存在於所有元素中? – Mackan
你可以按課程解析嗎?如果我爲每組輸入設置一個類,這是否可行? –