我有一个包含 RenderPartial 标记的视图。在部分视图中,我有一个表单,但客户端表单验证在服务器请求之前没有触发。服务器端验证工作正常。这很奇怪,因为我有其他观点,但没有完美工作的 RenderPartials。似乎当我包含 RenderParial 时,它似乎会导致验证停止工作。
顺便说一句 - 我已将两个 webconfig 设置都设置为 true:
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
此外,模型已更新为包含 [必需] 属性。这是一个快照:
[Required]
[CreditCard]
public string CardNumber { get; set; }
[Required]
[Display(Name = "Name on card")]
public string CardHolder { get; set; }
[Required]
public string Address { get; set; }
这是父代码段:
@if (ViewBag.tabvalue.Equals("billing"))
{
<div>
<p>
@{Html.RenderPartial("_BillingInfo");}
</p>
</div>
}
这是子部分视图(我删除了一些字段以减少复制量):
@model MVC4.Models.ClientCreditCard
@using (Html.BeginForm("CreditCard", "Client", FormMethod.Post, new { }))
{
@Html.AntiForgeryToken()
<fieldset style="color:white">
<legend></legend>
<div style="color:white;clear:left">@Html.ValidationSummary(true)</div>
<div class="editor-label">
@Html.LabelFor(model => model.CardNumber)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.CardNumber)
@Html.ValidationMessageFor(model => model.CardNumber)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.CardHolder)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.CardHolder)
@Html.ValidationMessageFor(model => model.CardHolder)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Address)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Address)
@Html.ValidationMessageFor(model => model.Address)
</div>
<p>
<input type="submit" value="Submit" />
</p>
</fieldset>
}
提前感谢您的帮助!