我正在构建一个流畅的界面,并想在 Controller 外部调用下面的代码...
return RedirectToAction("Activity");
我将如何设计这种方法?我有:
public FluentCommand RedirectOnSuccess(string url)
{
if (IsSuccess)
;// make call here...
return this;
}
注意:IsSuccess在这里设置:
public FluentCommand Execute()
{
try
{
_command.Execute();
IsSuccess = true;
}
catch (RulesException ex)
{
ex.CopyTo(_ms);
IsSuccess = false;
}
return this;
}
我称自己的界面流畅:
var fluent = new FluentCommand(new UpdateCommand(param,controller,modelstate)
.Execute()
.RedirectOnSucess("Actionname");
最佳答案
您可以将HttpContextBase
的实例存储为流利的接口(interface)内以及何时需要重定向的字段:
var rc = new RequestContext(context, new RouteData());
var urlHelper = new UrlHelper(rc);
context.Response.Redirect(urlHelper.Action(actionName), false);