c# - Save to DB in model method or controller -


i trying wrap head around mvc , how use it. appreciate question.

i created model ef db first. application adds data db. question is, should conducting saving db? in controller or in method lives within partial class of model?

in typical introductory book mvc present basic data-entry app simple data model, e.g: class personal data enter user, homecontroller index view called viewresult method called index , data entry view uses html helpers create form set of fields.

that view handled pair of viewresult methods in same homecontroller , 1 decorated [httpget], 1 presents view editable form user , , other decorated [httppost] , 1 receive , bind data edited view.

the binding done component of mvc called modelbinder , in viewresult method. there call ef's dbcontext save data. please keep in mind direct call dbcontext made in context of simple "learning app" , correct way create data manipulation layer it's own project , create service instantiated ioc library unity or ninject. hope helps.


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -