i was reading a post on EditorTemplates
from this url http://stackoverflow.com/questions/4872192/checkboxlist-in-mvc3-0
after seeing their code i just do not understand area like how it would work
view model:
public class MyViewModel
{
public int Id { get; set; }
public bool IsChecked { get; set; }
}
A controller:
public class HomeController : Controller
{
public ActionResult Index()
{
var model = new[]
{
new MyViewModel { Id = 1, IsChecked = false },
new MyViewModel { Id = 2, IsChecked = true },
new MyViewModel { Id = 3, IsChecked = false },
};
return View(model);
}
[HttpPost]
public ActionResult Index(IEnumerable<MyViewModel> model)
{
// TODO: Handle the user selection here
...
}
}
A View
(
~/Views/Home/Index.cshtml
):
@model IEnumerable<AppName.Models.MyViewModel>
@{
ViewBag.Title = "Home Page";
}
@using (Html.BeginForm())
{
@Html.EditorForModel()
<input type="submit" value="OK" />
}
and the corresponding Editor template
(
~/Views/Home/EditorTemplates/MyViewModel.cshtml
):
@model AppName.Models.MyViewModel
@Html.HiddenFor(x => x.Id)
@Html.CheckBoxFor(x => x.IsChecked)
see this code
@using (Html.BeginForm())
{
@Html.EditorForModel()
<input type="submit" value="OK" />
}
1) what this line will do
@Html.EditorForModel() ?
2) if this line would load a view called
MyViewModel from this location
/Views/Home/EditorTemplates/MyViewModel.cshtml
3) then how mvc engine would understand that it has to load view called
MyViewModel
from this location /Views/Home/EditorTemplates/
4) i saw people always create
EditorTemplates
folder in shared view but in this case it is created in home folder.....why ?
5) if there are so many other view in this location then how this line
@Html.EditorForModel()
would load this specific view
MyViewModel.cshtml
from this location
/Views/Home/EditorTemplates.
i am new in mvc and learning. so please help me to understand how the above code will work?
also please answer my 5 questions. thanks