这就是我想要的:
[GET("page/{id}/")]
public ActionResult Execute(Guid id, bool x = false, bool y = false,
bool z = false)
我想要bool可选的原因是我以后可以像这样使用这个方法:
return RedirectToAction<SomeController>(c => c.Execute(id, y: true));
不幸的是,当我尝试构建解决方案时,我得到以下错误:“表达式树可能不包含使用可选参数的调用或调用”和“表达式树可能不包含命名参数规范”。
我的问题是:是否有可能用控制器做类似的事情?路由中的可选参数怎么样?
答案 0 :(得分:2)
您可以使用模型类。 类似的东西:
public class ExecuteModel
{
public Guid id {get;set;}
public bool x {get;set;}
public bool y {get;set;}
public bool z {get;set;}
}
并将您的操作更改为:
public ActionResult Execute(ExecuteModel model)
{
...
}
,您的重定向将变为:
return RedirectToAction<SomeController>(c => c.Execute(
new ExecuteModel{id=id, y=true}));