Вопрос новичка ASP.NET MVC:
У меня есть следующая модель:
public class Customer
{
public string FirstName { get; set; }
public string LastName { get; set; }
public Address Address { get; set; }
}
И следующий вид для клиента:
<% using (Html.BeginForm()) { %>
First Name: <%=Html.TextBox("FirstName") %>
Last Name: <%=Html.TextBox("LastName") %>
<% Html.RenderPartial("AddressView", Model.Address); %>
<input type="submit" name="btnSubmit" value="Submit"/>
<%} %>
И следующий частичный вид для адреса:
<%=Html.DropDownList("CountryId", new SelectList(Country.GetAll(), "Id", "Name") })%>
<%=Html.DropDownList("CountrySubdivisionId", new SelectList(CountrySubDivision.GetByCountryId(Model.CountryId), "Id", "Name"))%>
И следующее действие контроллера:
[AcceptVerbs(HttpVerbs.Post)]
public ViewResult Index(Customer customer, Address address)
{
customer.Address = address;
ViewData.Model = customer;
return View();
}
Я надеялся, что действие будет работать с 1 параметром: customer, и мне не нужно будет переназначать customer.Address вручную. Однако при выполнении действия Customer.Address имеет значение null.
Я неправильно использую привязку модели или для моего действия требуются отдельные параметры для Customer и Address?