asp.net mvc路由问题
我有以下项目结构
http://img13.imageshost.ru/ img/2011/07/15/image_4e1fd08fe0c5d.png
UserController代码:
public class UserController : Controller
{
public ActionResult Login()
{
return View(ValidationResult.OK);
}
}
AdminController 代码:
public class AdminController : Controller
{
public ActionResult Login()
{
return View(ValidationResult.OK);
}
}
路由
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
当我尝试导航到 http://localhost:2334/admin/login 我收到“/admin/login”应用程序中的服务器错误,找不到请求的 URL:/admin/login/。 “
当我尝试时导航到 http://localhost:2334/user/login 我得到 **“服务器错误“/admin/login”应用程序。“HTTP 错误 404 - 未找到。 **
我什么都听不懂:(
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 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 :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不知道,可能是愚蠢的假设:您是否为控制器定义了适当的视图?
检查一下:
Don't know, probably stupid assumption: Did you define appropriate views for your controllers?
Check this:
首先,尝试通过右键单击操作方法并添加视图来在控制器的每个方法上创建 html 页面...
然后从解决方案资源管理器 app_start -> Routeconfig 设置要运行的默认页面。
请记住,如果您有家庭控制器,则无需在routeconfig中的家庭控制器后面编写控制器,只需添加家庭即可。
并在创建肯定有效的索引方法后添加视图。
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.
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.