My MVC 3 application needs to create new users.
I want to hard code the ApplicationId for the ApplicationId text box in the view.
Does anyone know how to do this?
The create method does not fetch any data:
public ActionResult Create()
{
return View();
}
<div class="editor-label">
@Html.LabelFor(model => model.ApplicationId)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ApplicationId)
@Html.ValidationMessageFor(model => model.ApplicationId)
</div>
Update
There is an option. To use a hidden field.
@Html.Hidden("ApplicationId", "ep006964-83a8-4f40-a569-d2d3296f005b")
Sure, in the controller action serving this view, you simply set the corresponding property on your view model:
Now the
EditorForwill display the correct value. There’s no way to force the value in the view. The whole point of editor templates is that they use the values that are set for your view model.