asp.net mvc - Whats the difference between Html.Label, Html.LabelFor and Html.LabelForModel -
what's difference between @html.label(), @html.labelfor() , @html.labelformodel() methods?
html.label gives label input name matches specified input text (more specifically, model property matching string expression):
// model public string test { get; set; } // view @html.label("test") // output <label for="test">test</label> html.labelfor gives label property represented provided expression (typically model property):
// model public class mymodel { [displayname("a property")] public string test { get; set; } } // view @model mymodel @html.labelfor(m => m.test) // output <label for="test">a property</label> html.labelformodel bit trickier. returns label for value of parameter represented model object. useful, in particular, custom editor templates. example:
// model public class mymodel { [displayname("a property")] public string test { get; set; } } // main view @html.editorfor(m => m.test) // inside editor template @html.labelformodel() // output <label for="test">a property</label>
Comments
Post a Comment