4

When I open the default MVC views(index and create) it work fine, I can add data and get data from the database. When I create a new view it don't work. It gets Http 404. This is even if I duplicate the create view, only with a different file name.

Error-message:

Server Error in '/' Application. 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.

I have follow some forum suggestions from people with similar problems, but it don't work.

I use MVC 5, EF6, VS2013 and my DB is a MS-sql.

Any suggestions that point me in the right direction is appreciated. Thanks!

ekad
  • 14,436
  • 26
  • 44
  • 46
Bjorn
  • 723
  • 2
  • 11
  • 29

3 Answers3

9

You should be accessing the view through an action method. So If you created your new view in ~/Views/Home/AboutMe.cshtml, You should add an action method like this in your HomeController.

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

Now you can access this like http://yourServerName/yourAppName/Home/AboutMe

If you want to have your action method in a different controller, You can specify the full view path. Ex : IF you want to add the action method to your Account controller,

public class AccountController : Controller
{
   public ActionResult AboutMe()
   {
      return View("~/Views/Home/aboutme.cshtml");
   }
}
Shyju
  • 214,206
  • 104
  • 411
  • 497
  • I would add to the answer that the Bjorn should read up on the concept of routing. With MVC when you go to a url such as /home/about the framework isn't looking for a particular page it is looking for a particular route and the default route would be the about action in the home controller. URL -> Routing Engine -> Correct Action -> View. – Gerald Davis Dec 18 '13 at 17:49
1

All the Views are linked to an Action in your controller.

http://www.asp.net/mvc/tutorials/mvc-5/introduction/adding-a-controller

http://www.asp.net/mvc/tutorials/mvc-5/introduction/adding-a-view

No Action in controller -> 404 error!

theLaw
  • 1,261
  • 2
  • 11
  • 23
0

Set as startup page now gives the wrong url, producing the 404

Jeremy
  • 1
  • 1
    If this is a comment on the original question or a new question, post it as such, not as an answer. – rfornal May 26 '15 at 00:41