I am working on ASP.NET MVC 4
application. I use EF 5
and Code First
. I have two entities with 1:N relation:
public class Menu
{
//some properties
public virtual ICollection<Document> Documents { get; set; }
}
and:
public class Document
{
//some properties..
public int MenuID { get; set; }
public virtual Menu Menu { get; set; }
}
I have Edit
view with [HttpPost]
and [HttpGet]
methods. When I pass the model through the GET
action like this :
Menu model = unitOfWork.MenuRepository.GetById(Id);
if (model != null)
{
return View(model);
}
everything is right, I can see that model contains 1 Documents
but then in my razor view if I simply try:
@Html.HiddenFor(m => m.Documents)
then when I submit the form to the Post
action I can see that the Documents
property is null.
How can keep Documents
persistent?