我有一个控制器动作,如下所示
public class HomeController : BaseController
{
public JsonResult Index(ComplexObject customObject)
{
...
}
...
}
这就是ComplexObject的样子
public class ComplexObject
{
public int? Id { get; set; }
...
}
以下是我在区域注册中定义的内容:
context.MapRoute(
"MyArea_default",
"MyArea/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new[] { "MyApp.Areas.MyArea.Controllers" }
);
我要做的是访问我的控制器操作,如
https://mysite.com/MyArea/ {value_of_id}
让我的ComplexObject for ComplexObject使用传入的id初始化一个新的ComplexObject。
这可能吗?互联网搜索根本没有帮助。
非常感谢您的帮助!
答案 0 :(得分:3)
是的,mvc会将路由参数绑定到复杂对象。你真的尝试过吗?