MVC: View to Model interaction example -


there're plenty of articles state in mvc architecture, view can interact directly model, namely ask data.

what real world example of view model interactions like? when programmer pass data via controller , when allow view retrieve directly model?

p.s. mvc heavily used in web development, but, far concerned, view interacting model through controller.

in example view using razor render. demonstrates view instantiating data request using jquery.get() after actionresult has been served client

this controller

public class homecontroller : controller {     public actionresult index()     {         return view();     }      [httpget]     public jsonresult getsomedata()     {         return json(new getsomedatamodel{             stringbar = "this stringbar. , boolbar: ";             boolbar = false;         });     } } 

this model data, not view.

public class getsomedatamodel {     public bool boolbar {get;set;}     public string stringbar {get;set;} } 

this view:

@{     viewbag.title = "home index page";     layout = "~/views/shared/_layout.cshtml"; }  @section scripts {     //and make second request controller data...     $.get( "@url.action("getsomedata", "home")", function( data ) {         alert( "load performed." );          console.log(data);     } } 

Comments