The view ‘Index’ or its master was not found or no view engine supports the searched locations

Problem

The view ‘Index’ or its master was not found or no view engine supports the searched locations. The following locations were searched:

  • ~/Views/Home/Index.aspx
  • ~/Views/Home/Index.ascx
  • ~/Views/Shared/Index.aspx
  • ~/Views/Shared/Index.ascx
  • ~/Views/Home/Index.cshtml
  • ~/Views/Home/Index.vbhtml
  • ~/Views/Shared/Index.cshtml
  • ~/Views/Shared/Index.vbhtml

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Solution

            The problem will occurs when we trying to access an action in the controller.  Consider the below action

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

The action index returns a view. Then it will check the corresponding view file in the following locations 

~/Views/Home/

 ~/Views/Shared/

Not only the location, it will check corresponding view with the action name that is Index is in our case, with following extensions

  • .aspx
  • .ascx
  • .aspx
  • .ascx
  • .cshtml
  • .vbhtml
  • .cshtml
  • .vbhtml

In the folder home or shared should contain a file with any of the extension above. 

After creating the view in the specified folder the controller will get the correct view, then view will be shown in the page and we can avoid this error. This is one of the error we face when we start mvc projects. But is a basic thing in mvc in .net, it will understood this with in some days after starting study of mvc in .net.

 

Leave a Reply

%d bloggers like this: