0

I'm trying to make my editor invisible? I got this but it is not working?

<%=Html.EditorFor(i => i.MyField),new { @visible = "false" })%>

1 Answer 1

2

The second parameter to EditorFor method is not HtmlAttributes but it is additionalViewData. you have to write your own EditorTemplate if you want to use additionalViewData to set visibility or something else for that matter. Look at this post to see how you can create custom editor templates
Edit: Supposing that Property MyField is of type string and you want to display it using text box, you have to create a partial view in EditorTemplates folder either in shared or any other view folder. in this view you can write something like

<%:Html.TextBox(string.Empty, Model, new{style = ViewData["style"]})%>

and in EditorFor method you can provide additionalViewData like

<%:Html.EditorFor(x=>x.MyField, new{style = "display:none;"})%>
Sign up to request clarification or add additional context in comments.

1 Comment

excellent! do you have a quick code sample? i am a bit of a mvc beginner:(

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.