12

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 Answers 2

23

Prefix it with '/Views' should help.

return View("~/Views/Items/Details.aspx");
Sign up to request clarification or add additional context in comments.

1 Comment

I ran into this today, used this suggestion but also needed to add the ".cshtml" extension.
1

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.

2 Comments

Actually, you can. It's not a good design IMHO, but it does work.
Sorry, I edited it in the meanwhile, because I noticed I was wrong: I was suggesting that you could not call views by absolute path.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.