0

I am having trouble making my ASP.NET MVC 3 View bind data back to a Model.

The typical objects such as string ContactName and string Title are being sent back successfully.

My public List<KeyValuePair<string, ListingTranslation>> ExpirimentToRemove object however isn't being sent back for some reason.

The following is contains code of the specific objects that aren't being binded successfully.

<div>
     <ul class="nav nav-tabs">
        @for (int i = 0; i < Model.ExpirimentToRemove.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>
     <div class="tab-content" style="overflow: visible;">
         @for (int i = 0; i < Model.ExpirimentToRemove.Count; i++)
         {
             <div class="tab-pane@i == 0 ? ' active' : ''" id="@@Model.Translations.Keys.ToList()[i]">
                @Html.TextBoxFor(m => Model.ExpirimentToRemove[i].Value.Title)
                @Html.TextBoxFor(m => Model.ExpirimentToRemove[i].Value.FullDescription)
                @Html.TextBoxFor(m => Model.ExpirimentToRemove[i].Value.PreviewDescription)
             </div>
          }
      </div>

1 Answer 1

1

The trick for a list of items to be bound back is to have hidden fields.

Here is a great article explaining it in detail

Example:

<input type="hidden" name="products.Index" value="caliente" />
<input type="text" name="products[caliente].Name" value="Salsa" />
<input type="text" name="products[caliente].Price" value="1.23" />

The only other way is to manually manipulate the name attribute for the element that corresponds with the object path for the given item in List<T>.

Sign up to request clarification or add additional context in comments.

1 Comment

I'll try that now! Thank you! Stay tuned please!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.