asp.net mvc 3 - MVC3 Testing ModelState excluding property errors in a view -
I did a search on Google and Stack Overflow but could not find the answer.
I have the following in my opinion
@if (! Html.ViewData.ModelState.IsValid) {@ Html.ValidationSummary (true)
I am only interested in model errors but when the errors are found, the test will come true. How do I just test model errors?
I may need to clarify here, I & lt; Br / & gt;
Want to test to stop is a property error but there is no model error.
If you go to source of validation source, you can
IEnumerable & lt; ModelState & gt; ModelStates = null; If (Leave Property Emaarors) {ModelState MS; HtmlHelper.ViewData.ModelState.TryGetValue (htmlHelper.ViewData.TemplateInfo.HtmlFieldPrefix, MS Out); If (MS! = Faucet) {Model States = New ModelState [] {MS}; }} And {Model States = htmlHelper.ViewData.ModelState.Values; }
So I think you can make a method like that
public static bool modelStatus modelerrars (this HtmlHelper htmlHelper) {ModelState ms; HtmlHelper.ViewData.ModelState.TryGetValue (htmlHelper.ViewData.TemplateInfo.HtmlFieldPrefix, MS Out); Return ms! = Null; }
Comments
Post a Comment