Error in creating view in Asp.Net MVC 4

Agnib

I am new in Asp.Net MVC and has been assigned a project. I have created a view named as "webMaster.cshtml" in Views/Shared folder. My controller name is: "EmployeeController" and Action name is: "ViewEmployees".

public class EmployeeController : Controller
{
    //
    // GET: /Employee/

    public ActionResult ViewEmployees()
    {
        return View("webMaster.cshtml");
    }

}

View Page

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>@ViewBag.Title - Practice MVC</title>
</head>
<body>
    <h2>webMaster</h2>
</body>
</html>

Error while running the project

Server Error in '/' Application.

The view 'webMaster.cshtml' or its master was not found or no view engine    supports the searched locations. The following locations were searched:
~/Views/Employee/webMaster.cshtml.aspx
~/Views/Employee/webMaster.cshtml.ascx
~/Views/Shared/webMaster.cshtml.aspx
~/Views/Shared/webMaster.cshtml.ascx
~/Views/Employee/webMaster.cshtml.cshtml
~/Views/Employee/webMaster.cshtml.vbhtml
~/Views/Shared/webMaster.cshtml.cshtml
~/Views/Shared/webMaster.cshtml.vbhtml

Now, my question is why it is searching for: "~/Views/Shared/webMaster.cshtml.cshtml" Instead, it should search for "~/Views/Shared/webMaster.cshtml"

Please help in sorting this out.

Thanks.

Dave van Herten

MVC will take your string and look for it in a whole whack of places like you can see in the error message. As such, it doesn't want you to dictate the extension.

Change it to:

public ActionResult ViewEmployees()
{
    return View("webMaster");
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Customised error messages are not translated in ASP.NET MVC 4

ASP.NET - MVC 4 using a variable from a controller to a view

ASP.Net MVC4 HandleError not rendering view specified

Weird Error Upgrading ASP.NET MVC from 4 to 5

How to show error in View if the Controller fails ? ASP.NET MVC

ASP.NET MVC View inside view

ASP.NET MVC 4 - Update Model from View

ASP.NET MVC4 "Getting Started" Configuration Error

ASP.NET MVC 4: keeping Index as defaul view

Partial view not showing in the view in asp.net mvc4

ASP.NET MVC 4 Custom Handle Error

JSON transmission from the controller to the view in ASP.NET MVC 4

Pass model to a view with view name in ASP.Net MVC 4

Creating Custom Layout in ASP.Net MVC3 using Razor View

Including script specific to an ASP.NET MVC4 view or partial view

updating portion of asp.net MVc 4 view with partial view

Creating reusable HTML view components using Razor in ASP.NET MVC

Secure the View in ASP.NET MVC4 : Forms Authentification

Display a view as image in another view ASP.NET MVC4

Repeating Partial View in ASP.net MVC 4

ASP.NET MVC 4 Send a model - View to Controller

Dynamic creating controls in asp.net mvc4

asp.net-mvc - creating html helper extension to pass view data

AJAX with partial view MVC 4 ASP.net C#

ASP.NET MVC 4 error with Google CalendarAPIv3

Using Unity in ASP.NET MVC 4 - Dependency injection error

ASP.NET MVC - Determine if field has an error in Razor view

ASP.NET MVC creating an entity with already exists error

Having ASP.NET MVC partial view without creating a new file

TOP Ranking

HotTag

Archive