从业务逻辑类重定向asp.net的MVC页 [英] Redirect asp.net mvc page from business logic class

查看:201
本文介绍了从业务逻辑类重定向asp.net的MVC页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打电话给我的商业逻辑层内的静态方法,对于目的,我不会在这里提了,需要做的重定向本身,而返回的信息反馈给控制器做重定向。

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.

我想我需要使用HttpContext对象,但我与创建路线挣扎。我不能简单地做context.Response.Redirect(someController /的someMethod),因为我需要包括动作控制器的参数,我的M发送用户。

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 = 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

推荐答案

非常难看,抗MVC,不要在业务层等做......不过既然你问:

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

这篇关于从业务逻辑类重定向asp.net的MVC页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆