Silverlight Student
Silverlight Student

Reputation: 4118

cshtml file could not be found although it is under Shared folder

I have a cshtml under Shared folder. I am doing a RedirectToAction() to this page but its not looking for this file in Shared folder. Its only looking in the appropriate folder under views. It uses to look into Shared folder before and I have no idea what I could have changed that breaking lookup. Any ideas?

Upvotes: 1

Views: 866

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039438

You cannot do a RedirectToAction to a view. You are doing (as it name suggests) a redirect to an action. It is this action that returns a view. By default it will look for views in the ~/Views/ControllerName and ~/Views/Shared. So let's suppose that you have the following action which performs a redirect:

public class HomeController: Controller
{
    public ActionResult Index()
    {
        return RedirectToAction("Index", "Products");
    }
}

which would redirect to the Index action on the Products controller:

public class ProductsController: Controller
{
    public ActionResult Index()
    {
        return View();
    }
}

Now the Index.cshtml view could be in ~/Views/Products/Index.cshtml or in ~/Views/Shared/Index.cshtml.

Upvotes: 2

Related Questions