I’m a beginner about Razor, and sometimes I get stuck with really simple things.
I have this foreach loop:
@foreach (dynamic item in ViewBag.EAList)
{
<li>
@using (@Html.BeginForm("Duplicate, "Daily"))
{
<p>@item.AuthorComment</p>
@Html.Hidden("EstadoDeAlmaID", @item.EAID)
@Html.Hidden("PosterID", Session["id"].ToString())
<input type="submit" value="Send" />
}
</li>
}
This line:
@Html.Hidden("EstadoDeAlmaID", @item.EAID)
Doesn’t work, and I don’t know how to make it work, I tried many ways, without @, with (–), with @(–)…
Could someone help me to display the dynamic value in my hidden field?
In addition, if someone know about a good Razor samples websites, I would be very thankful.
To avoid the Extension methods cannot be dynamically dispatched exception, use a model instead of
ViewBagso you will not be usingdynamicobjects (this will avoid all the unnecessary casting in the View and is more in line with MVC style in general):In your action when you return the view:
In your view, the first line should be:
Then just do: