asp.net mvc - MVC index method with change to viewmodel -


i want know best way of writing index method in mvc when need make changes model before passing view.

i picked technique somewhere can pass in model intend pass view, , make changes it, have noticed model binding kicks in when passing index method, , validation fires, when there no need because initial load.

for example, more correct:

public actionresult index(viewmodel model) {     model.someproperty = "mynewvalue";      return base.index(model); } 

or

public actionresult index() {     viewmodel model = new viewmodel();      model.someproperty = "mynewvalue";      return base.index(model); }     

and there should know implications of using either one?

with initial loads, latter makes more sense. controllers in mvc newed each , every single time use them. there no persistence whatsoever. first option, http requests need pre-existing knowledge of api. so, recommendation have view model come persistence layer.

public actionresult index() {     var vm = /* persistence layer */     vm.someproperty = "newval";     return view(vm); } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -