{"id":28463,"date":"2020-10-29T14:37:36","date_gmt":"2020-10-29T14:37:36","guid":{"rendered":"https:\/\/www.globalizationpartners.com\/?p=28463"},"modified":"2020-11-11T07:58:46","modified_gmt":"2020-11-11T07:58:46","slug":"asp-net-mvc-pattern","status":"publish","type":"post","link":"https:\/\/www.globalizationpartners.com\/2020\/10\/29\/asp-net-mvc-pattern\/","title":{"rendered":"Microsoft ASP.NET Model View Controller (MVC) Pattern"},"content":{"rendered":"<h2>Model View Controller (MVC) Design Pattern<\/h2>\n<p>A Model View Controller is a software design pattern that\u2019s commonly used for developing user interfaces. This architectural pattern helps to separate concerns and layers. It divides the program logic into three interconnected elements:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignright wp-image-28279\" style=\"float: right; margin: 0.5em 0 0.5em 1em;\" src=\"https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2020\/10\/asp.net-mvc-pattern-1.jpg\" alt=\"ASP.NET MVC Pattern \" width=\"379\" height=\"252\" \/><\/p>\n<ol>\n<li>Model \u2013 Provides data and associated logic to the view as the database table definition<\/li>\n<li>View &#8211; Renders the model to the view with HTML tags or elements<\/li>\n<li>Controller \u2013 Interacts with the model and views, and acts as a server-side method defining with input and output that will appear with a page as view<\/li>\n<\/ol>\n<p>Using the MVC pattern for websites, requests are routed to a controller, which is responsible for working with the model to perform actions and\/or retrieve data. The controller chooses the view to display and provides it with the model. The view renders the final page based on the data in the model. The authentication system includes libraries, a database, and template pages for handling logins, including multi-factor authentication and external authentication, or OAuth with Facebook, Google, and more.<\/p>\n<p>&nbsp;<\/p>\n<h2>Model Responsibilities<\/h2>\n<p>The model in an MVC application represents the state of the application and any business logic or operations that should be performed by it. Business logic should be encapsulated in the model, along with any implementation logic for persisting the state of the application. Strongly typed views typically use view model types designed to contain the data to display on that view. The controller creates and populates these view model instances from the model.<\/p>\n<p>The following code demonstrates an example of how a model class can look like.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-28464 aligncenter\" src=\"https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2020\/10\/asp.net-mvc-pattern.jpg\" alt=\"ASP.NET MVC Pattern \" width=\"624\" height=\"365\" srcset=\"https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2020\/10\/asp.net-mvc-pattern.jpg 624w, https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2020\/10\/asp.net-mvc-pattern-300x175.jpg 300w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2>View Responsibilities<\/h2>\n<p>Views are responsible for presenting and displaying the content through the user interface. They use the Razor view engine to embed .NET code in HTML markup language. There should be minimal logic within views, and any logic in them should relate to presenting content. If you need to perform a great deal of logic in view files in order to display data from a complex model, consider using a view component, view model or view template to simplify the view.<\/p>\n<p>The following code demonstrates an example of how a view class can look like.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-28469 aligncenter\" src=\"https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2020\/10\/Microsoft-asp.net-mvc-pattern.jpg\" alt=\"Microsoft ASP.NET MVC Pattern \" width=\"624\" height=\"298\" srcset=\"https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2020\/10\/Microsoft-asp.net-mvc-pattern.jpg 624w, https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2020\/10\/Microsoft-asp.net-mvc-pattern-300x143.jpg 300w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2>Controller Responsibilities<\/h2>\n<p>Controllers are the components that handle user interactions, work with the models, and at the end, select a view to render to display it. In an MVC application, the view only displays information or data values. The controller handles and responds to user input and interactions. In the MVC pattern, the controller is the initial entry point and is responsible for selecting which data model types to work with and which view to render in the HTML page.<\/p>\n<p>The following code demonstrates an example of how a controller class can look like.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-28479 aligncenter\" src=\"https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2020\/10\/mvc-pattern.jpg\" alt=\"MVC Pattern\" width=\"506\" height=\"557\" srcset=\"https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2020\/10\/mvc-pattern.jpg 506w, https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2020\/10\/mvc-pattern-273x300.jpg 273w\" sizes=\"(max-width: 506px) 100vw, 506px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2>ASP.NET MVC Application In Summary<\/h2>\n<p>The Model View Controller software design pattern is commonly used for developing user interfaces. For more information about MVC, refer to <a href=\"https:\/\/dotnet.microsoft.com\/apps\/aspnet\/mvc\">https:\/\/dotnet.microsoft.com\/apps\/aspnet\/mvc<\/a>.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Resource:<\/strong><\/p>\n<p><a href=\"https:\/\/dotnet.microsoft.com\/apps\/aspnet\/mvc\">https:\/\/dotnet.microsoft.com\/apps\/aspnet\/mvc<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Model View Controller (MVC) Design Pattern A Model View Controller is a software design pattern that\u2019s commonly used for developing user interfaces. This architectural pattern helps to separate concerns and layers. It divides the program logic into three interconnected elements: Model \u2013 Provides data and associated logic to the view as the database table definition [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":28720,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[1502,309,667],"_links":{"self":[{"href":"https:\/\/www.globalizationpartners.com\/wp-json\/wp\/v2\/posts\/28463"}],"collection":[{"href":"https:\/\/www.globalizationpartners.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.globalizationpartners.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.globalizationpartners.com\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.globalizationpartners.com\/wp-json\/wp\/v2\/comments?post=28463"}],"version-history":[{"count":5,"href":"https:\/\/www.globalizationpartners.com\/wp-json\/wp\/v2\/posts\/28463\/revisions"}],"predecessor-version":[{"id":28487,"href":"https:\/\/www.globalizationpartners.com\/wp-json\/wp\/v2\/posts\/28463\/revisions\/28487"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.globalizationpartners.com\/wp-json\/wp\/v2\/media\/28720"}],"wp:attachment":[{"href":"https:\/\/www.globalizationpartners.com\/wp-json\/wp\/v2\/media?parent=28463"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.globalizationpartners.com\/wp-json\/wp\/v2\/categories?post=28463"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.globalizationpartners.com\/wp-json\/wp\/v2\/tags?post=28463"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}