ASP.NET CORE MVC - Shared\Error.cshtml

Bob H 0 Reputation points
2024-12-25T17:22:18.84+00:00

Hi,

I'm really new to ASP.NET Core MVC. I normally use ASP.Net Web forms (.Net Framework). One thing I could not figure out about MVC is the out-of-the box project templage (ASP.Net core mvc with .net 9 template in visual studio) has the Error.cshtml view in the Shared folder. This Error.cshtml view is obviously called by Controllers\HomeController. How does the "return View(new ..)" know to render the Error.cshtml view? Where is the setting for this?

User's image

When right click the Error() controller > Go to View, it opens the Error.cshtml page.

User's image

Thanks in advace

Bob

.NET
.NET
Microsoft Technologies based on the .NET software framework.
4,008 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,704 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 68,486 Reputation points
    2024-12-25T21:58:28.4833333+00:00

    MVC uses conventions over configuration. The views are filenames. There is a search pattern and order defined to match the view with the action name defined in route table. Shared is one of the paths searched.

    https://learn.microsoft.com/en-us/aspnet/core/mvc/views/overview?view=aspnetcore-9.0

    if you are coming from webforms, you might prefer razor pages. In razor pages the views are compiled and have a code behind. While MVC is stable, razor pages is receiving new features.

    https://learn.microsoft.com/en-us/aspnet/core/razor-pages/?view=aspnetcore-9.0&tabs=visual-studio

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Bob H 0 Reputation points
    2024-12-25T21:52:41.7333333+00:00
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.