简体   繁体   English

ValidationSummary与视图的顺序不同

[英]ValidationSummary is not in the same order as the view

I have a standard view set up, model bound fields with required attributes and some custom modelstate.AddModelErrors however, the summary doesnt display the errors in the same order as the view. 我有一个标准的视图设置,具有必需属性的模型绑定字段和一些自定义modelstate.AddModelErrors,但是摘要未按与视图相同的顺序显示错误。

My summary errors are as follows: 我的摘要错误如下:

  • The Title field is required. “标题”字段是必填字段。
  • The First name field is required. 名字字段为必填项。
  • The Last name field is required. 必须填写姓氏字段。
  • The Date of birth field is required. 出生日期字段为必填项。
  • At least one contact number is required 至少需要一个联系电话
  • The Gender field is required. 性别字段为必填项。

The last 2 should be the other way around as the "At least one contact number is required" is for a field which is after Gender field on screen and also added through modelstate.AddModelErrors. 最后两个应该是相反的,因为“至少需要一个联系电话”是针对屏幕上“性别”字段之后的字段,并且也是通过modelstate.AddModelErrors添加的。 Everything ese is in the correct order. 一切都是正确的顺序。

I'd expect the model errors to be in order and anything added manually to go in at the end. 我希望模型错误能够按顺序进行,并且任何手动添加的错误都可以在末尾输入。 Is this not the case or do I need to write my own validation summary partial? 是不是这样,还是我需要部分编写自己的验证摘要?

Yes, you need to write your own validation summary partial. 是的,您需要编写自己的验证摘要部分。

At least that's what I had to do. 至少那是我要做的。 I also had to derive my own class from ModelError , add a priority property to it, and then use that for ordering in the partial. 我还必须从ModelError派生我自己的类, ModelError添加一个优先级属性,然后将其用于部分中的排序。 A lot of work all in all, so think about whether you really need to do this, as in reality most users won't ever see the full list of validation errors, but just one or two messages. 总而言之,有很多工作要做,因此请考虑一下您是否真的需要这样做,因为实际上,大多数用户永远不会看到完整的验证错误列表,而只会看到一两个消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM