我正在我的业务逻辑层中调用一个静态方法,出于我不会在这里提到的目的,它需要自己进行重定向,而不是将信息返回给 Controller 来进行重定向。
我想我需要使用 HttpContext 对象,但正在努力创建路由。我不能简单地做 context.Response.Redirect("someController/someMethod) ,因为我需要包含我将用户发送到的 Action Controller 的参数。
假设这是正确的:
HttpContext context = HttpContext.Current;
任何人都可以提供一些有关如何使用以下对象创建路由的语法帮助:
new { Controller = "MyController", action = "Index", OtherParm="other value" }
TIA
最佳答案
非常丑陋,反 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);
关于asp.net-mvc - 从业务逻辑类重定向asp.net mvc页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2066351/