To display the information of two tables that are related one to one, I need to implement view models as follows:
public class EstateViewModel
{
public long Id { get; set; }
public string Name { get; set; }
public EstateInfoViewModel InfosModel { get; set; } = new EstateInfoViewModel();
}
public class EstateViewModel
{
public string Describe{ get; set; }
}
After defining the view models, I put the HTML codes in the view as below:
@Html.TextboxFor(x => x.Name);
@Html.TextBoxFor(x => x.InfosModel.Describe)
After execution, the names of the text boxes will be displayed in the browser as follows:
<input id="Id" name="Id" type="text">
<input id="Name" name="Name" type="text">
<input id="Describe" name="Describe" type="text">
My problem is that the "describe" textbox is not binding to InfosModel.Describe in the action because its name in the view is Describe and not InfosModel.Describe
I tried use new {id="GiveName", Name = "GiveName"} but it doesn't work and doesn't change the name of Describe property.