Tips for Working Efficiently with Views in Model-View-Controller

working with views in model view controller n.w
1 / 19
Embed
Share

"Explore how to effectively utilize layout views, regular views, and strongly-typed views in Model-View-Controller (MVC) development. Learn about the Layout view, Regular Views, Strongly-typed Views, and the benefits they offer for efficient web application design."

  • MVC Views
  • Layout Views
  • Strongly-typed Views
  • Web Development
  • ASP.NET

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Working with views in Model-View-Controller Submitted to: Dr. Morris Liaw Presented by: Samineni, Akhil (Presentation id: 8) Tulasi Venkata, Deepika (Presentation id: 9) Chava, Sravya (Presentation id: 11) Thati, Sravika (Presentation id: 17) Kirti (Presentation id: 19)

  2. Table of contents Layout views in MVC How to work with layout views The layout.cshtml file Regular views in MVC The home/index.cshtml view Strongly-typed views in MVC The home/contact.cshtml view Server controls in MVC Controls in Order/Index.cshtml view 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. Redirection in MVC 11. Examples of redirection in controls 12. Working with FormCollection object 13. How to work with model binding 14. Benefits of using controls in MVC

  3. Layout view in MVC UI in an application contains common parts that remains unchanged throughout the application. These parts includes the logo, header, left navigation bar, right bar or footer section. ASP.NET MVC introduced a Layout view which contains these common UI parts. This facilitates the user for not writing the same code in every page. It is same as the master page of the ASP.NET webform application. It allows the user to define a common site template, which can be inherited in multiple views. The development speed and easy maintenance. layout view eliminates duplicate coding and enhances

  4. How to work with layout views These are the ASP.NET features linked with layout view: It provides content blocks, RenderPage, RenderBody and also supports PageData dictionary. Content blocks, which are files that contain HTML-formatted content to be inserted in multiple pages. Layout pages, which are pages that contain HTML-formatted content that can be shared by pages on the website. Methods like RenderPage, RenderBody, Rendersection that helps the user in inserting the page elements. The PageData dictionary that allows user to share data between content blocks and layout pages.

  5. The_Layout.cshtml file

  6. Regular views in MVC It is a view that's rendered within another view. The HTML output generated by executing the regular view is rendered into the calling (or parent) view. In case of regular views the files are saved with .cshtml file extension.

  7. The home/index.cshtml view

  8. Strongly- typed views in MVC It is view that is render using specific types of model objects. User can bind any class as model to view using strongly typed views. User also have access model properties on the view. Furthermore, use can use data associated with model to render controls.

  9. The home/contact.cshtml view

  10. Server controls in MVC Server controls provides Event modelling. It supports an event-driven programming style that is like Windows applications. Server controls reduces the complexity of managing state by using view state and server-based controls. They provide Page-based architecture. This structure can make it easy to create pages that implement common tasks. The ASP.NET community has made available hundreds of server controls and components that reduce development time.

  11. Controls in Order/Index.cshtml view

  12. Working with redirection Redirecting is necessary when there are more than one page in the web site. It will allow us to add navigation links to the pages and help us in processing postback as well. For this, HTML anchor elements could be used. HTML anchor uses link attribute for serving this purpose. MVC also uses Post-Redirect-Get (PRG) for avoiding back-button and refreshing the page.

  13. Examples of redirection in controls

  14. Working with FormCollection object FormCollection is a way to collect data from a view to a collection. It uses POST index for retrieving the values from the FormCollection object. It also used GET index for redirecting. The following figure shows adding AutoPostback using jQuery

  15. Example for working with FormCollection object

  16. Model binding in MVC Model binding is a mechanism ASP.NET MVC uses to create parameter objects defined in controller action methods. The parameters can be of any type, from simple to complex ones. It simplifies working with data sent by the browser because data is automatically assigned to the specified model. Without this mechanism, developers would need to manually assign values to model properties. This which would result in writing almost the same code in every action method.

  17. Model binding in Cart controller

  18. Benefits of using views in MVC Views help to establish a Separation of Concerns (SoC) design within an MVC app by separating the user interface markup from other parts of the app. The app is easier to maintain because it's better organized. Views are generally grouped by app feature. This makes it easier to find related views when working on a feature. It's easier to test the user interface parts of the app because the views are separate units. Due to better organization, it's less likely that you'll accidently repeat sections of the user interface.

  19. Thanks

Related


More Related Content