Asp.net mvc 在ASP.NETMVC中,有更好的方法吗?
在使用ASP.NETMVC3Web应用程序时,我发现需要有这样一条路径。。。。 其中Edit是命令,4是成人的ID 我最终选择了以下路线Asp.net mvc 在ASP.NETMVC中,有更好的方法吗?,asp.net-mvc,asp.net-mvc-3,Asp.net Mvc,Asp.net Mvc 3,在使用ASP.NETMVC3Web应用程序时,我发现需要有这样一条路径。。。。 其中Edit是命令,4是成人的ID 我最终选择了以下路线 routes.MapRoute("ParentPortal", "ParentPortal/{action}/{type}/{id}", New With {.controller = "ParentPortal", .action = "Index", .type = UrlParameter.Optional, .id =
routes.MapRoute("ParentPortal", "ParentPortal/{action}/{type}/{id}",
New With {.controller = "ParentPortal", .action = "Index", .type = UrlParameter.Optional, .id = UrlParameter.Optional})
以及以下行动
<Authorize(Roles:="Parent")>
Public Function Adult(ByVal type As String, ByVal id As Integer?) As ActionResult
Select Case type.ToLower
Case "edit"
Throw New NotImplementedException()
Case "new"
Throw New NotImplementedException()
Case Else
Throw New NotImplementedException()
End Select
End Function
作为ActionResult的公共函数(ByVal类型为字符串,ByVal id为整数?)
选择Case type.ToLower
案例“编辑”
抛出新的NotImplementedException()
案例“新”
抛出新的NotImplementedException()
其他情况
抛出新的NotImplementedException()
结束选择
端函数
这是推荐的做法吗 你看过MVC领域吗 你看过MVC领域吗 第二次使用MVC区域。您现在所做的不是与标准ASP.NET MVC设计模式内联的,而是依赖于神奇的字符串 相反,创建一个名为“ParentPortal”的新区域。添加一个名为“成人”的控制器,其中包含编辑和新操作。最后,向MVC注册新区域。即:
[Authorize(Roles="Parent")]
public class Adult : Controller{
public ActionResult Edit(int id){
..stuff..
return View(model);
}
public ActionResult New(int id){
..stuff..
return View(model);
}
}
AreaRegistration.RegisterAllAreas();
借调使用MVC区域。您现在所做的不是与标准ASP.NET MVC设计模式内联的,而是依赖于神奇的字符串 相反,创建一个名为“ParentPortal”的新区域。添加一个名为“成人”的控制器,其中包含编辑和新操作。最后,向MVC注册新区域。即:
[Authorize(Roles="Parent")]
public class Adult : Controller{
public ActionResult Edit(int id){
..stuff..
return View(model);
}
public ActionResult New(int id){
..stuff..
return View(model);
}
}
AreaRegistration.RegisterAllAreas();
因为这是一个更完整的答案,所以我会标记它。你的建议就是我最后要做的,但我使用的是VB.Net,所以我不得不跳过一些障碍来让它工作。因为这是更完整的答案,我会标记它。你的建议就是我最后要做的,但我使用的是VB.Net,所以我不得不跳过一些障碍来让它工作。