Search code examples
asp.net-mvcmodel-view-controllerhtml-helper

How to display name of MVC model?


I have a class like this:

Public Class AuthKey
    <StringLength(45, ErrorMessage:="Name must not less then 5 characters and not exceed 45 characters.", MinimumLength:=5)>
    <Display(Name:="Name", Description:="Authentication name.")> _
    Public Property name As String
End Class

I'd like to view the property display name and description, not the property value. I try to both @html.display("Name") or @html.display("Description") and @html.displayfor(function (m) m.name) all show nothing. How to show it?


Solution

  • add model class in your view page after that try like this

     @Html.DisplayNameFor(model => model.name)
    

    how-to-access-the-model-from-the-view