将 Addition 参数传递给 IControllerFactory.CreateController
我正在使用 MEF 在 MVC3 应用程序中动态加载控制器。 在导出元数据中,我指定了两个元数据约束
EX:
[ExportMetadata("controllerName", "APSR")]
[ExportMetadata("controllerVersion", "1.0.0.0")]
在我的“主”mvc 应用程序中,我使用 RedirectToAction 方法(响应用户单击下拉列表)
[HttpPost]
public ActionResult Index(Models.HomeViewModel selected)
{
//ViewData.Add("Version", selected.AvailableWorkflows[int.Parse(selected.SelectedWorkflow)].Version);
return RedirectToAction("Create", selected.AvailableWorkflows[int.Parse(selected.SelectedWorkflow)].Controller);
}
如何将所需的版本号传递给我的控制器工厂? 由于 IControllerFactory.CreateController 方法仅参数除外:
IController IControllerFactory.CreateController(System.Web.Routing.RequestContext requestContext, string controllerName)
I am using MEF to dynamically load controllers in an MVC3 app.
In the export metadata I am specifying two meta data constraints
EX:
[ExportMetadata("controllerName", "APSR")]
[ExportMetadata("controllerVersion", "1.0.0.0")]
In my "main" mvc app, I am using a RedirectToAction method (In reponse to a user click on a dropdown)
[HttpPost]
public ActionResult Index(Models.HomeViewModel selected)
{
//ViewData.Add("Version", selected.AvailableWorkflows[int.Parse(selected.SelectedWorkflow)].Version);
return RedirectToAction("Create", selected.AvailableWorkflows[int.Parse(selected.SelectedWorkflow)].Controller);
}
How can I pass the desired version number to my Controller factory? Since the IControllerFactory.CreateController method only excepts to paramters:
IController IControllerFactory.CreateController(System.Web.Routing.RequestContext requestContext, string controllerName)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想您需要一些额外的路线数据,并在创建控制器时阅读这些数据。
例如,我可以将路由定义为:
现在,当我创建控制器的实例时,我可以从
RequestContext.RouteData
集合中获取该版本项:您只需确保传递版本作为路由的参数。
I would imagine you need some additional route data, and reading that when creating your controller.
For instance, I could define a route as:
Now, when I create an instance of my controller, I can grab that version item from the
RequestContext.RouteData
collection:You just need to ensure that you are passing the version as an argument to the route.