ASP.NET MVC4 "resource not found" when adding new view

I am using the default "internet application" that Visual Studio 2010 will generate to test out MVC4.

I have added a new View inside a folder:

\Views\NewFolder\NewPage.cshtml

..and have appended a link to this new View in my "_Layout.cshtml" file.

<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
<li>@Html.ActionLink("NewPage", "NewPage", "NewFolder")</li>

..whilst the first three links, which were autogenerated, work fine, the last one is giving me a "resource not found" error.

Upvotes: 1

Views: 5360

Answers (4)

Hardik Shah
Hardik Shah

Reputation: 1

1) First you Need to create Controller for View then create View.

2) Right click inside method then click on add view link.

Step 1

enter image description here

Step 2

enter image description here

Upvotes: -1

hutchonoid
hutchonoid

Reputation: 33305

You need to have the corresponding Controller and Action in place.

For the three above they all have a HomeController, with Index, About and Contact actions. These have corresponding views within a View/Home folder, taking the convention from the HomeController name for the folder.

As Avinash states you need the NewFolderController but also a NewPage action, if you return a non-named view this will default to your NewPage view.

Here is the code needed to get it working:

  public class NewFolderController : Controller
   {
      public ActionResult NewPage() {
      return View();
      }

    }

You are really better off reading through the tutorial here and learning the conventions:

http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/intro-to-aspnet-mvc-4

Upvotes: 6

Sai Avinash
Sai Avinash

Reputation: 4753

You should have a controller named..NewFolderController . ASP.net MVC is Strictly relys on naming convention.

Hope it helps..

Upvotes: 0

C M
C M

Reputation: 703

First you Need to create Controller for View then create View.

or else you can use existing view of controller.

Create a Newcontroller then create Action method NewPage.

Right click inside method then click on add view link.

or

then create a folder in named 'New' inside 'Views' folder then add view(.cshtml) with name NewPage inside New folder.

Upvotes: 0

Related Questions