从业务逻辑类重定向asp.net mvc页面

时间:2022-09-24 23:41:35

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.

我想我需要使用HttpContext对象,但我正在努力创建路由。我不能简单地做context.Response.Redirect(“someController / someMethod)因为我需要包含我发送给用户的动作控制器的参数。

Assuming this is correct:

假设这是正确的:

HttpContext context = HttpContext.Current;

Can anyone please provide some syntax help with how to create a route using an object like:

任何人都可以提供一些语法帮助,如何使用如下对象创建路由:

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

TIA

TIA

1 个解决方案

#1


12  

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

非常丑陋,反MVC,不要在业务层等做...但是因为你问:

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

#1


12  

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

非常丑陋,反MVC,不要在业务层等做...但是因为你问:

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