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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -