How to send and retrieve in the controller

Posted by user281180 on Stack Overflow See other posts from Stack Overflow or by user281180
Published on 2010-04-02T12:07:14Z Indexed on 2010/04/02 12:13 UTC
Read the original article Hit count: 180

Filed under:

I have the folowing code in my view, however, I can see that I don`t have the values in the controller. What is wrong? In the view I have,

<%
    using (Html.BeginForm())
    {%>
       <%=Html.TextBox("Addresses[0].Line1") %>
       <%=Html.TextBox("Addresses[0].Line2")%>
       <%=Html.TextBox("Addresses[1].Line1")%>
       <%=Html.TextBox("Addresses[1].Line2")%>

        <input type="submit" name="submitForm" value="Save products" />
        <%
    }
%>

My classes are as follows:

public class Customer
{
    public string FirstName { get; set; }
    public string Lastname { get; set; }
    public List<Address> Addresses { get; set; }
    public Customer()
    {
        Addresses = new List<Address>();
    }
}

public class Address
{
    public int Line1 { get; set; }
    public int Line2 { get; set; }
}

My controller as follows:

public ActionResult Index()
    {
        return View();
    }

    [HttpPost]
    public ActionResult Index(Customer customer)
    {
        return View();
    }

© Stack Overflow or respective owner

Related posts about mvc