1

I am using ASP.Net MVC 5 for web development. I have added many Views and they are working. But if I try to add a new View, it cannot be navigated by browser i.e. 404 error occurred. But the rest of the Views are working correctly.

I tried to add new Views in distinct controllers but they have the same problem.

Please help me to solve this issue.

Rahul Sharma
  • 7,768
  • 2
  • 28
  • 54
Burhan uddin
  • 21
  • 1
  • 6

1 Answers1

0

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

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");
   }
}
Joey Phillips
  • 1,543
  • 2
  • 14
  • 22