I have all most the same question as him ASP.NET MVC partial views: input name prefixes
I am tring to create CRUD operations for this data entities:
public class UserViewModel
{
protected virtual Id {get; set;}
public virtual string Login { get; set; }
public virtual string Password { get; set; }
public virtual ZipCodeViewModel ZipCode { get; set; }
}
Zip Code entity:
public class ZipCodeViewModel
{
public virtual string City { get; set; }
public virtual string State { get; set; }
public virtual string Zip { get; set; }
}
I also have partial view ZipCode which used UserViewModel.ZipCode:
@model ZipCodeViewModel
@Html.TextBoxFor(x => x.Zip, new { id = "ZipCode", name = "ZipCode.Zip", maxlength = "5" })
I am going to use ZipCodePartialView in another Page (for example user).
@model UserViewModel
.....
@{Html.RenderPartial("Zipcode", Model.ZipCode);}
When MVC save User ZipCode field Zip is empty.
So question is how I can add model prefix to the patrial View?