Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing views with absolute paths on ASP.NET MVC

I'm trying to access a view in this way:

return View(@"~\Items\Details.aspx");

and I get this error:

The view '~\Items\Details.aspx' or its master could not be found. The following locations were searched: ~\Items\Details.aspx

On the ItemsController, in the Details action, returning View() works just fine. Why can't I access that view from another controller?

like image 767
pupeno Avatar asked Sep 14 '09 14:09

pupeno


People also ask

What is relative and absolute path in ASP NET?

In ASP.NET server controls that reference resources, you can use absolute or relative paths as you do for client elements. If you use relative paths, they are resolved relative to the path of the page, user control, or theme in which the control is contained.

What is a view in MVC?

A view is an HTML template with embedded Razor markup. Razor markup is code that interacts with HTML markup to produce a webpage that's sent to the client. In ASP.NET Core MVC, views are.cshtml files that use the C# programming language in Razor markup. Usually, view files are grouped into folders named for each of the app's controllers.

What is a view in ASP NET Core?

A view is an HTML template with embedded Razor markup. Razor markup is code that interacts with HTML markup to produce a webpage that's sent to the client. In ASP.NET Core MVC, views are .cshtml files that use the C# programming language in Razor markup.

What are the benefits of using an AspView component?

View components provide the same SoC that controllers and views offer. They can eliminate the need for actions and views that deal with data used by common user interface elements. Like many other aspects of ASP.NET Core, views support dependency injection, allowing services to be injected into views.


1 Answers

Prefix it with '/Views' should help.

return View("~/Views/Items/Details.aspx");
like image 115
Jan Jongboom Avatar answered Nov 16 '22 02:11

Jan Jongboom