sarsnake
sarsnake

Reputation: 27703

MVC 3, Asp.net 4 - Error in application - the resource can not be found

I just created an empty application, added a view, a controller and ran it.

I am getting the following error:

"The resource cannot be found." Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

My code: TestController.cs

namespace WOSubmittal.Controllers
{
    public class TestController : Controller
    {

        public ActionResult Index()
        {
            return View();
        }

    }
}

View located under Views/Test

Index.cshtml

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

I put a breakpoint to the Index() routine and it doesn't even get hit. Any ideas?

Upvotes: 1

Views: 2644

Answers (3)

William
William

Reputation: 330

Change this line in the Web.config file:

<httpRuntime enable="false" targetFramework="4.5"/>

to

<httpRuntime enable="true" targetFramework="4.5"/>

Upvotes: 0

Pablo Claus
Pablo Claus

Reputation: 5920

Change this in public static void RegisterRoutes(RouteCollection routes)

new { controller = "Home", action = "Index", id = UrlParameter.Optional } 

for this:

new { controller = "Test", action = "Index", id = UrlParameter.Optional }

in your Global.asax.cs

Upvotes: 1

Paul Alan Taylor
Paul Alan Taylor

Reputation: 10680

Change TestlController to TestController.

When looking for a view for your controller, MVC will use the name of your controller, without the word Controller, when attempting to resolve it.

From the code you've given, MVC would look in Views/Testl, not Views/Test.

Upvotes: 1

Related Questions