domain driven design - How can I get a property as an Entity in Action of Asp.Net Mvc? -
i'd know how can property entity, 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 category property ? it's fill view ? asp.net mvc know how fill object id ?
thanks!
this 1 of reasons why it's bad bind directly entities. consider
public class productform { public int id { get; set; } public string name { get; set; } public string categoryid { get; set; } } public actionresult save(productform form) { var product = new product { id = form.id, name = form.name, category = database.getcategory(form.categoryid) }; }
in case of view models above, may ok use custom model binders automatically entities id database. see here sample implementation (in s#arp architecture) binds ids entities database. think better go simpler implementation above.
you can use automapper simplify form->entity mapping.
Comments
Post a Comment