Mvc2 验证摘要和所需元数据
源代码 ...
问题是,如果我使用流畅的模型元数据提供程序指定所需的元数据,例如这=>
public class Foo
{
public string Bar { get; set; }
}
public class FooModelMetadataConfiguration : ModelMetadataConfiguration<Foo>
{
public FooModelMetadataConfiguration()
{
Configure(x => x.Bar)
.Required("lapsa") ;
}
}
并将其写入我的视图=>
<% Html.BeginForm(); %>
<%= Html.ValidationSummary() %>
<%= Html.TextBoxFor(x=>x.Bar) %>
<% Html.EndForm(); %>
并将其添加到家庭控制器=>
[HttpPost]
public ActionResult Index(Foo foo)
{
ViewData["Message"] = "Welcome to ASP.NET MVC!";
return View(foo);
}
它将输出这个 html =>
<div class="validation-summary-errors">
<ul>
<li>lapsa</li>
<li>The Bar field is required.</li>
</ul>
</div>
我不明白为什么会出现第二个错误以及如何忽略它。
System.Web.Mvc.Extensibility框架的作者回复=>
我认为这是 ASP.NET MVC 的一个已知问题,我不记得阅读它的确切位置,我建议您通过 Codeplex 将问题发布到 ASP.NET MVC 问题跟踪器中。
但在我在问题跟踪器上发布任何内容之前 - 我想首先了解到底出了什么问题。
有什么帮助吗?
source code...
Thing is, if i specify required metadata using fluent modelmetadata provider like this=>
public class Foo
{
public string Bar { get; set; }
}
public class FooModelMetadataConfiguration : ModelMetadataConfiguration<Foo>
{
public FooModelMetadataConfiguration()
{
Configure(x => x.Bar)
.Required("lapsa") ;
}
}
And write this into my view =>
<% Html.BeginForm(); %>
<%= Html.ValidationSummary() %>
<%= Html.TextBoxFor(x=>x.Bar) %>
<% Html.EndForm(); %>
And add this to home controller =>
[HttpPost]
public ActionResult Index(Foo foo)
{
ViewData["Message"] = "Welcome to ASP.NET MVC!";
return View(foo);
}
It will output this html =>
<div class="validation-summary-errors">
<ul>
<li>lapsa</li>
<li>The Bar field is required.</li>
</ul>
</div>
I can't understand why 2nd error is rendered and how to omit it.
Author of System.Web.Mvc.Extensibility framework replied with =>
I think this is a known issue of asp.net mvc, i could not remember the exact location where I have read it, I suggest you post the issue in asp.net mvc issue tracker over codeplex.
But before i post anything on issue tracker - i would like to understand first what exactly is wrong.
Any help with that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
现在已修复。
It's fixed now.