【发布时间】:2011-12-06 21:00:33
【问题描述】:
我想设置一个 ASP.NET MVC 路由,如下所示:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{idl}", // URL with parameters
new { controller = "Home", action = "Index", idl = UrlParameter.Optional } // Parameter defaults
);
路由看起来像这样的请求...
Example/GetItems/1,2,3
...到我的控制器操作:
public class ExampleController : Controller
{
public ActionResult GetItems(List<int> id_list)
{
return View();
}
}
问题是,我该如何设置才能将idl url 参数从string 转换为List<int> 并调用适当的控制器操作?
我见过related question here 使用OnActionExecuting 预处理字符串,但没有更改类型。我不认为这对我有用,因为当我在控制器中覆盖 OnActionExecuting 并检查 ActionExecutingContext 参数时,我看到 ActionParameters 字典已经有一个带有空值的 idl 键 -据推测,尝试从字符串转换为 List<int>... 这是我想要控制的路由部分。
这可能吗?
【问题讨论】:
标签: c# asp.net asp.net-mvc iis-7 onactionexecuting