I have an ASP.NET MVC 3 application that binds data to a Model. Simple objects within the Model are working perfectly like: ContactName and Telephone.
I am doing this by simply having: @Html.TextBoxFor(m => m.ContactName)
The Model contains a Dictionary object which isn’t getting binded with my current implementation.
Can anyone give me an example of how I can do this? The current code I have for binding to a Dictionary is:
<div>
@*TABS*@
<ul class="nav nav-tabs">
@for (var i = 0; i < Model.Translations.Count; i++)
{
<li class="@i == 0 ? 'active' : ''"><a href="#@Model.Translations.Keys.ToList()[i]" data-toggle="tab">@Model.Translations.Keys.ToList()[i]</a></li>
}
</ul>
@*TABCONTENT*@
<div class="tab-content" style="overflow: visible;">
@foreach (var translation in Model.Translations)
{
for (var i = 0; i < Model.Translations.Count; i++)
{
<div class="@i == 0 ? 'active' : ''" id="@translation.Value.CultureCode">@translation.Value.Title</div>
}
@Html.TextBoxFor(m => translation.Value.Title[]);
@Html.TextBoxFor(m => translation.Value.FullDescription);
@Html.TextBoxFor(m => translation.Value.PreviewDescription);
}
</div>
</div>
Any help is highly appreciated.
use “your list property”[index].value.id
example
if you have:
you should write in view:
updated: