0
我对IE和ASP.NET MVC 4 Data Annotations有一个很奇怪的问题。ASP.NET MVC一些数据注释验证显示在IE的页面加载中
其中一些似乎只在IE(9/7和8/7标准模式中的9)中初始页面加载时显示其服务器端错误消息。受影响的人似乎是一些StringLength和RegularExpression,但并非所有人都有其他数据注释,例如要求不显示他们的消息。
我已经定制了如何验证消息插入客户端,所以他们肯定是服务器端错误。
有没有人知道为什么会发生这种情况?我完全困惑。
我已经打过电话ModelState.Clear()在我的操作方法,但这似乎并没有解决问题..
我使用PRG模式,但其使我的形式摹一部分是儿童行动,这可能是问题吗?响应
代码评论:
public ActionResult MyForm()
{
var cp = GetComponentPresentation();
var model = new MyFormModel(cp);
model.ComponentId = cp.Component.Id;
LoadModel(model);
return PresentationView(model);
}
private void LoadModel(MyFormModel model)
{
string titleTypesTcmId = ConfigHelper.TitleTypesKeywordId.FormatWith(ConfigHelper.PublicationId);
model.TitleKeywords = TaxonomyService.GetTaxonomyKeywordChildrenNames(titleTypesTcmId)
.Select(x => new SelectListItem() { Text = x, Value = x }).ToList();
}
的查看HTML是250线,我没有时间来匿名化它。所以这里是一个文本框的片段,它似乎失败了验证。
<div class="row">
@using (Html.BeginForm("MyForm", "MyFormController", FormMethod.Post, new { id = "MyForm", @class = "form ajax", data_ajax_error=Html.GetPlainTextValue(Model.Component, "error_message") }))
{
<input type="hidden" name="ComponentId" value="@Model.Component.Id"/>
<fieldset class="paddingright">
<legend>Your Details</legend>
<div class="row field">
@Html.LabelForRequired(m => m.NationalInsuranceNumber, Html.Resource("Labels_Form_NINumber"))
@Html.TextBoxFor(m => m.NationalInsuranceNumber, new { placeholder=Html.Resource("Placeholder_Form_NINumber") })
@Html.ValidationMessageFor(m => m.NationalInsuranceNumber, null, new { @class = "error"})
</div>
<!-- SNIP -->
<div class="submit-container no-js-hidden">
<button type="submit" value="Step2" class="btn-green customsubmit" name="FormButton">
<span class="content">Next step ></span>
</button>
</div>
</fieldset>
}
请问您可以发布您的控制器代码和查看html? – heads5150
@ heads5150根据要求尽可能多地添加。 –