kareemborai
kareemborai

Reputation: 394

The resource cannot be found (Error in ASP.NET MVC 5)

I've manually added a view in the Home folder called "Test.cshtml".

When I opened that view in the browser it shows me the error: The resource cannot be found.

I tried the following solutions but still getting that error:

1- Right click on The Project Name > Properties > Specific Page > set it to: "Home/Test".

2- In RouteConfig class > RegisterRoutes method > Default MapRoute > set: controller = "Home", action = "Test".

Upvotes: 5

Views: 36373

Answers (2)

CoolDev
CoolDev

Reputation: 9

For my case, it's very strange. I change one action method in the controller to take in 2 parameters instead of 4 as was before but forgot to update the ajax call to the view and it caused this error.

Before: data: { officer: officer, "scid": scid, "timein": timein, "timeout": timeout } - causes error due to parameter mismatch

Now: data: { officer: officer, "scid": scid } - working fine now.

Upvotes: -1

Ofiris
Ofiris

Reputation: 6141

You need to add an Action called Test in your Home controller.

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

Visual Studio can help you generating the view for the action, right click on the Test method and Add View...

You can read more about Routing and Attribute Routing in this MSDN article.

Also a good read - How URLs Are Matched to Routes

Upvotes: 13

Related Questions