How can I get a property as an Entity in Action of Asp.Net Mvc ?

Posted by Felipe on Stack Overflow See other posts from Stack Overflow or by Felipe
Published on 2010-04-28T16:12:58Z Indexed on 2010/04/28 18:47 UTC
Read the original article Hit count: 162

Hi all, i'd like to know how can I get a property like an entity, for example:

My Model:

public class Product {

   public int Id { get; set; }
   public string Name { get; set; }
   public Category Category { get; set; }

}

View:

Name: <%=Html.TextBoxFor(x => x.Name) %>
Category: <%= Html.DropDownList("Category", IEnumerable<SelectListItem>)ViewData["Categories"]) %>

Controller:

public ActionResult Save(Product product)
{
   /// produtct.Category ???
}

and how is the category property ? It's fill by the view ? ASP.Net MVC know how to fill this object by ID ?

Thanks!

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about domain-driven-design