MVC @ Html.Display ()
I have something like:
<input type="text" name="TerrMng" id="TerrMng"/> in HTML. Which is equivalent to the above using @ Html.Display?
I tried using: @Html.Display("TerrMng", TerrMng)
but failed. Note that I like to use @ Html.Display, but I'm not sure how to translate the ID value so that it displays.
This should do the trick if you just want to display the data and not allow the user to edit the information.
@Html.DisplayFor(m => m.TerrMng); Edit:
what-is-the-html-displayfor-syntax-for is another stackoverflow thread question that can give you some tips.
Edit:
TerrMng does not exist on the Load page, so you cannot use Html.Display . You need to create it and fill its value with the value obtained from jQuery. In this case, you will need to do the following:
HTML
@Html.Display("TerrMng"); // This creates the label with an id of TerrMng JQuery
$("#TerrMng").val(TerrMng); // This puts the value of the javascript variable into the label The Display method is not intended to create input fields. Do you want to use:
@Html.TextBoxFor(m => m.TerrMng); or template helper :
@Html.EditorFor(m => m.TerrMng); I assume you want to use model binding. If not, if you really just want to use the helper to easily enter an input tag, use:
@Html.TextBox("TerrMng"); This will be sent to the client:
<input id="TerrMng" type="text" value="" name="TerrMng"> The first two methods above will result in the same html if model.TerrMng was "" or String.Empty . If for some reason you do not need the value attribute, you need to enter it yourself.