0

I have in my edit form displayed: Username, TimeZone, Customer...

I don't whant to be able to edit username, just display his name.

This code I use in View:

    <label>Username </label> 
    <div class="editor-field">
        @Html.EditorFor(model => model.username)
    </div>

So what to put instead EditorFor, that will display username (just for reading, not for editing).

2 Answers 2

1

Why not just use @Html.DisplayFor instead? This will just display the username as a label. Or, if you wish to use @Html.EditorFor or @Html.EditorForModel, you can create a custom editor template for your username property, and in the editor template, just display the content instead of enabling editing.

Also, I would recomment you exclude this property during model binding by using [Bind(Exclude="username")] with your model parameter in your POST action method, to protect from injection attacks. More about this here.

Sign up to request clarification or add additional context in comments.

Comments

0

find solution:

@Html.TextBoxFor(model => model.username, new {disabled = "disabled", @readonly = "readonly" })

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.