c# - ASP.NET MVC common model for different controller methods -
i having hard time understanding way mvc behaves. in controller class created model , initialized main actionmethod. after call controller method , turns out model null. why that?
now seems can use them once passing database info views. necessary modify/query database? know in cases makes sense it, keep these parts separate.
edit: here's code:
public class testcontroller : controller { testmodel model; public actionresult index() { model = new testmodel(); return view(model); } public actionresult othermethod { // here access/modify created model, null return view(); } }
you should use html helpers bind properties of model in view
or use @html.editorformodel() helper. create ui , binding entire model
Comments
Post a Comment