Dhanush K
What is ViewStart?

What is ViewStart in MVC(ModelViewController)?

By Dhanush K in ASP.NET on Jan 12 2022
  • Ashok Kumawat
    Jan, 2022 17

    You can follow this link to know about ViewStart in MVC.

    https://www.c-sharpcorner.com/UploadFile/618722/viewstart-page-in-Asp-Net-mvc-3/

    • 2
  • Sardar Mudassar Ali Khan
    Feb, 2023 28

    Code that is run at the start of each Razor Page’s execution is found in the _ViewStart.cshtml file. All Razor Pages contained in the same folder as the ViewStart file or any of its subfolders are impacted by the ViewStart file. Hierarchical files exist in ViewStart. The file system will execute files stored in subfolders before those situated higher up.

    Setting the layout page for each Razor Page is the most frequent application of the ViewStart file. Server-side code must be contained in a Razor code block because the ViewStart file is a Razor Page:

    1. @{
    2. Layout = "_Layout";
    3. }

    • 1
  • Prahlad Signh
    Apr, 2024 20

    Here's how it works:Default Layout: One common use of ViewStart is to define the default layout for views within a folder or the entire application. By specifying a layout in ViewStart, you can avoid repeating the layout declaration in every individual view file within that folder or the application.Shared Settings: Besides layout, ViewStart can also contain shared settings or configurations that need to be applied to multiple views. For example, setting the page title, specifying the master page or layout file, including common scripts or stylesheets, etc.Hierarchy: ViewStart files follow a hierarchical structure. This means you can have multiple ViewStart files in different folders within your project, and the settings defined in a parent ViewStart file are inherited by child folders unless overridden.

    • 0
  • Vishal Yelve
    Jul, 2022 8

    In simple term I can say that if suppose I am adding 100 views in my project and want to add this common layout in each view then I have to set this layout property in each view.In future if I will change this common layout name or location I have to make changes in each view too, which is little bit hectic.So Razor View Engine introduced a new layout named _ViewStart which is applied on all view automatically. Razor View Engine firstly executes the _ViewStart and then start rendering the other view and merges them.In this situation we need not to set the layout property in each view.

    • 0
  • Kelly Peters
    Mar, 2022 6

    _ViewStart.cshtml file is used to define the common layout page for all the views you add to your project. If you add a view, you see below dialog box to provide the View name, View Engine and Layout or master page.

    AFFORDABLE SEO SERVICES

    • 0
  • Faina Smirnoff
    Feb, 2022 21

    ACCORDING TO MY RESEARCH THE VIEWSTART.CSHTML PAGE IS A SPECIAL VIEW PAGE CONTAINING THE STATEMENT DECLARATION TO INCLUDE THE LAYOUT PAGE. SEO company in Cincinnati

    • 0
  • Arvind Yadav
    Jan, 2022 28

    a special view page containing the statement declaration to include the Layout page

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS