0

I have a problem with my viewmodel. I have a DropDownList with many translation values (pattern here)

In my controller - HTTPGET:

 public ActionResult Edit(int id) {

            int DropDownListValueId = id;

            SelectListViewModel viewmodel = new SelectListViewModel(0, DropDownListValueId);          

            return View(viewmodel);

        } 

In my view:

  <% using (Html.BeginForm())
       {%>
        <%: Html.ValidationSummary(true)%>

        <fieldset>
            <legend>Fields</legend>      

            <%foreach (var item in Model.DropDownListValue.DropDownListValue_Translation)
              {%>                  
                    <%: Html.TextBoxFor(model => item.Name) %><br />           

            <%  } %>

            <p>
                <input type="submit" value="Save" />
            </p>
        </fieldset>

    <% } %>

In my controller, HTTPPOST:

[HttpPost]
public ActionResult Edit(SelectListViewModel viewmodel)
{                
    return View();
} 

My problem: data is not passed in httppost; I think the problem is foreach in my view?

Community
  • 1
  • 1
Akawan
  • 103
  • 1
  • 2
  • 11

1 Answers1

0

In my view, typed viewmodel:

<legend>Contacts</legend>
      <% for (int i = 0; i < Model.Contacts.Count; i++) { %>

            <%: Html.EditorFor(model => model.Contacts[i],"Contact") %>

        <% } %>

With this, I bind my list to the controller!

zondo
  • 19,901
  • 8
  • 44
  • 83
Akawan
  • 103
  • 1
  • 2
  • 11