c# - Using MVC, how do I design the view so that it does not require knowledge of the variables being set by the controller? -


Assume that I have a theoretical MVC framework that viewData Object uses the view in my controller, say I have some code (in pseudocode):

  function GetClientInfo () {// database var client = database. Bring a bunch of data from the gateclient (); Var ClientOur = Database. Gate client operators (); Var ClientWistlist = Database GETClientWishList (); // ViewData object sets a bunch of variables in ViewData.set ("Client", Client); ViewData.set ("client order", client order); ViewData.set ("Client Wishlist", Client Washlust); ShowView ("ClientHomePage"); }   

and then in my ClientHomePage view, I display data like this:

  & lt; P & gt; Welcome back, [ViewData.get ("Customer") FirstName.] And lt; / P & gt; & Lt; P & gt; Your order history: & lt; / P & gt; & Lt; Ul & gt; [Html.ToList (ViewData.get ("Client Orders")]  

Your Wishlist: ul & gt; [ HTML ToList (ViewData.get ("clientWishList")]

I understand this to understand MVC (Please correct me if I am wrong ). How does this know how to find out the objects from the ViewData object until it is not known what the controller is putting in the first place? What if some magic Refactor on any of Does the wires in the controller, but forget to change it in the scene, and get a runtime bug instead of a compile time error? This is a big violation of separating the concerns.

This Where I am thinking that a View MODEL may work in:

  class clientinfo {client client; list client order; catalog customer wishlist}}   

Then creates an example of the controller ClientInfo and in v The binding contract between the viewmodel controller and the view is created, and the scene is not required to know what the controller is doing, as long as it believes that the controller is properly populating ViewModel First of all, I thought it was MVVM, but to read more about it, it seems as much as MVC-VM is in my mind, because MVVM does not exist in the controller.

My question is, what can I not understand about MVC vs MVVM here? Is referring to variables in the ViewData by magic strings; is not really a bad idea? And how does one insure that the change in the controller will not adversely affect the view?

Your understanding is that the MVC is incorrect, this model is for View Controller but you can use the model in your example Do not miss. This is a typed unit that returns to the view for rendering. ASP.NET will use the type of scenes you type in MVC, which also write the model in the view, so it is checked in time compilation . This eliminates the need for magic string (the second part of your question).

In MVVM you have a Model View Vertical This view is a way of directly modulating the modal through a view on the UI layer, which is done a lot in WPF. It takes the place of the need of the controller and it is generally 1-to-1 mapping with the UI. This is just an alternative mechanism that solves the same problem (the separation and separation of problems), but it is better suited for technology.

There are some useful information that can help in understanding the difference.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -