How do I get the collection of Model State Errors in ASP.NET MVC?

后端 未结 9 1268
孤城傲影
孤城傲影 2020-11-27 09:48

How do I get the collection of errors in a view?

I don\'t want to use the Html Helper Validation Summary or Validation Message. Instead I want to check for errors an

9条回答
  •  情深已故
    2020-11-27 10:22

    Got this from BrockAllen's answer that worked for me, it displays the keys that have errors:

        var errors =
        from item in ModelState
        where item.Value.Errors.Count > 0
        select item.Key;
        var keys = errors.ToArray();
    

    Source: https://forums.asp.net/t/1805163.aspx?Get+the+Key+value+of+the+Model+error

提交回复
热议问题