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?
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.
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.
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.
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.
Prefix it with '/Views' should help.
return View("~/Views/Items/Details.aspx");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With