You don’t call two models on a single view but you have some alternate to perform this operation such like that:
1. Use Other view that binds with other model and call with help of
@Html.Action()
method.
@Html.Action("ActionName", "ControllerName",new { id = Model.Id })
2. Use Other partial view that populate with other model and call with help of
@Html.Partial()
or
@Html.EditiorFor<>()
.
@Html.Partial("_partialView", Model)
3. Define property of sub model type in base model which binds and access value using base model for example, define to model which binds on single view
public class EmployeeModel
{
public EmployeeModel()
{
Address = new AddressModel();
}
public int Id { get; set; }
public string Name { get; set; }
public AddressModel Address{get;set;}
}
public class AddressModel
{
public string City { get; set; }
public string Country { get; set; }
}
Define a view to use these models
@model EmployeeModel
@* from base model *@
@Html.TextBoxFor(model=>model.Name)
@* from child model *@
@Html.TextBoxFor(model => model.Address.City)