Reputation: 141
I tried below method, but it does not work:
<%: Html.HiddenFor(m => m.Email, (string)ViewData["Email"])%>
<%: Html.HiddenFor(m => m.Email, new{value = (string)ViewData["Email"]})%>
Plz adivce.
Upvotes: 0
Views: 3641
Reputation: 1039458
In ASP.NET MVC data is set by the controller. A view is there only to display the data passed by a controller. Also I would recommend you using strongly typed views and view models instead of ViewData.
public ActionResult Index()
{
var model = new SomeViewModel
{
Email = "[email protected]"
};
return View(model);
}
And in the view simply:
<%= Html.HiddenFor(m => m.Email) %>
Upvotes: 2