简体   繁体   中英

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".

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM