Accessing views with absolute paths on ASP.NET MVC

2019-04-20 17:44发布

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?

2条回答
做个烂人
2楼-- · 2019-04-20 18:20

Prefix it with '/Views' should help.

return View("~/Views/Items/Details.aspx");
查看更多
一纸荒年 Trace。
3楼-- · 2019-04-20 18:28

You can make the Items view a shared one (you put it in the Views/Shared folder), then you can just call View("Items") and it will work.

查看更多
登录 后发表回答