I am late to the game. i am struggling with EditorFor.
Instead of using the template to display the name of the entity in a textbox, the name is written to screen. It appears to be writing the first property of the object as in my real project a guid is being written.
How can I use the editorfor while specifying the template?
Home Controller
public ActionResult Index()
{
HomeModel homeModel = new HomeModel();
homeModel.RoomModels = new List<RoomModel>();
homeModel.RoomModels.Add(new RoomModel() { RoomName = "Room-1" });
homeModel.RoomModels.Add(new RoomModel() { RoomName = "Room-2" });
homeModel.RoomModels.Add(new RoomModel() { RoomName = "Room-3" });
return View(homeModel);
}
Home Model
public class HomeModel
{
public List<RoomModel> RoomModels { get; set; }
}
Room Model
public class RoomModel
{
public string RoomName { get; set; }
}
/Views/Home/Index.cshtml
@model MVC.Temp.Models.Home.HomeModel
<h1>Home</h1>
<div id="RoomModels">
@Html.EditorFor(m => m.RoomModels, "_RoomModelEditor")
</div>
/Views/Home/_RoomModelEditor.cshtml
@model MVC.Temp.Models.Home.RoomModel
@Html.TextBoxFor(x => x.RoomName)
Current Output:
