Created a new view in MVC 5, opening the new view results in HTTP 404

拈花ヽ惹草 提交于 2019-12-01 19:04:20

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");
   }
}

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!

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!