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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -