I want to use EditorTemplates to create a view which displays many models forms so I can create them and relation them.
To do that I have created a House_Extended model:
public class Extended_House
{
public Extended_House() {}
public House House { get; set; }
public Person Owner { get; set; }
}
In my Create.cshtml I have:
@Html.EditorFor(model => model.House)
@Html.EditorFor(model => model.Owner)
In the Extended_HouseController I want to pass the Cities to be displayed in the House dropdownlist:
public ActionResult Create()
{
ViewBag.Id_City = new SelectList(db.City, "Id_", "Name");
return View();
}
The House.cshtml is in the EditorTemplates file of Extended_HouseView
@model myproject.Models.House --> here's my problem. I cant get the selectList values. How can I get them?
<div class="form-group">
@Html.LabelFor(model => model.Id_City, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("Inmueble.Id_City", String.Empty)
@Html.ValidationMessageFor(model => model.Id_City)
</div>
</div>
Is there any way I can use dropdown lists with editor templates like this?