开发者

Redirect asp.net mvc page from business logic class

I am calling a static method within my business logic layer that, for purposes I won't mention here, needs to do the redirecting itself rather returning information back to the controller to do the redirect.

I figure I need to use the HttpContext object but am struggling with creating the route. I can't simply do context.Response.Redirect("someController/someMethod) because I need to include parameters for the action controller that I"m sending the user to.

Assuming this is correct:

HttpContext context = HttpContext.Current;

Can anyon开发者_运维百科e please provide some syntax help with how to create a route using an object like:

new { Controller = "MyController", action = "Index", OtherParm="other value" }

TIA


Very ugly, anti-MVC, don't do in business layer, etc... but since you are asking:

var context = new RequestContext(
    new HttpContextWrapper(System.Web.HttpContext.Current), 
    new RouteData());
var urlHelper = new UrlHelper(context);
var url = urlHelper.Action("Index", new { OtherParm = "other value" });
System.Web.HttpContext.Current.Response.Redirect(url);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜