繁体   English   中英

在 controller 之外调用 return RedirectToAction(“Activity”)

[英]calling return RedirectToAction(“Activity”) outside controller

我正在构建一个流畅的界面,并想在我的 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的实例存储为流利界面中的字段,并且在需要重定向时:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM