I am practicing ASP.NET MVC using vs 2013, and writed a simple project, with one controller and view.
controller code:
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
return View();
}
public ActionResult ShowMyHome()
{
return View("MyHome");
}
}
"MyHome" view Code:
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Hello World</title>
</head>
<body>
<div>
Welcome my first MVC page
</div>
</body>
</html>
RouteConfig code:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Home",
url: "Home",
defaults: new { controller = "Home", action = "ShowMyHome", id = UrlParameter.Optional }
);
}
}
when i run and set url line on "http://mySite/Home/ShowMyHome", it works well. but when i run and set url line on "http://mySite/Home", i get a error:
The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Home/Index.aspx
~/Views/Home/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Views/Home/Index.cshtml
~/Views/Home/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml
It looks like the "Home" routing doesn't work.