c# - mvc edditorfor disable -


i using code below allow users name added want admin user able add user name manually. common user view username apperars fro them, how go making interlinked data in editttor can viewd in label

current code put in editor

@html.editorfor(model => model.username) 

code changed

  @if (viewbag.isadmin == false)             {                 @html.labelfor(model => model.username, new { id = "username" })             }             else             {                 @html.editorfor(model => model.username)             } 

rendered code

<label id="username" for="username">username</label> <input id="username" class="text-box single-line" type="text" value="" name="username" data-val-required="please enter user name." data-val="true"> 

@if (viewbag.isadmin) {     @html.editorfor(model => model.username) } else {     @model.username     @html.hiddenfor(model => model.username) } 

this easy way.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -