Problem with asp.net mvc routing
I have the following project structure
http://img13.imageshost.ru/img/2011/07/15/image_4e1fd08fe0c5d.png
UserController code:
public class UserController : Controller
{
public ActionResult Login()
{
return View(ValidationResult.OK);
}
}
AdminController code:
public class AdminController : Controller
{
public ActionResult Login()
{
return View(ValidationResult.OK);
}
}
Routes
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with开发者_StackOverflow中文版 parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
When I try to navigate to http://localhost:2334/admin/login I get "Server Error in '/admin/login' Application. The resource cannot be found. Requested URL: /admin/login/"
When I try to navigate to http://localhost:2334/user/login I get **"Server Error in '/admin/login' Application."HTTP Error 404 - Not Found. **
I can't understand anything :(
Don't know, probably stupid assumption: Did you define appropriate views for your controllers? Check this:
/Views/Admin/Login.cshtml
/Views/User/Login.cshtml
First of all try to create html pages on each method of controller by right click on action method and add view...
Then from solution explorer app_start -> routeconfig set your default page which gona run.
routes.MapRoute(
"YourControllername", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Yourcontrollername", action = "methodname", id = UrlParameter.Optional }
);
Remember you dont need to write controller behind your Home controller in routeconfig for ex just add home if you have homecontroller.
and add view after creating index method that will work for sure.
精彩评论