在控制器外调用返回RedirectToAction(“Activity”)

时间:2011-08-11 09:43:01

标签: c# asp.net-mvc-2

我正在构建一个流畅的界面,并希望在我的控制器外面调用下面的代码......

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");

1 个答案:

答案 0 :(得分:4)

您可以将HttpContextBase的实例作为字段存储在您的流畅界面中,以及何时需要重定向:

var rc = new RequestContext(context, new RouteData());
var urlHelper = new UrlHelper(rc);
context.Response.Redirect(urlHelper.Action(actionName), false);