How to read property data annotation value in .NET MVC

前端 未结 6 1556
独厮守ぢ
独厮守ぢ 2020-12-17 04:43

I Just starting out w/ ASP.NET MVC 3 and I am trying to render out the following HTML for the string properties on a ViewModel on the create/edit view.



        
6条回答
  •  抹茶落季
    2020-12-17 05:34

    You can get the StringLength Validator from within an Editor Template, here are some examples:

    https://jefferytay.wordpress.com/2011/12/20/asp-net-mvc-string-editor-template-which-handles-the-stringlength-attribute/

    What I used and tested, as a result from the article above can be seen in my answer below (tested with MVC 5, EF 6) :

    ASP.NET MVC 3 - Data Annoation and Max Length/Size for Textbox Rendering

    Without being specific, I've personally had some mixed results with attempts to implement some other approaches, and I don't find either claimed method particular long; however, I did think some of the other approached looked a little "prettier".

提交回复
热议问题