Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc ASP MVC:ActionFilter属性->;RedirectToRouteResult始终重定向到HTTP GET_Asp.net Mvc_Redirect_Action Filter - Fatal编程技术网

Asp.net mvc ASP MVC:ActionFilter属性->;RedirectToRouteResult始终重定向到HTTP GET

Asp.net mvc ASP MVC:ActionFilter属性->;RedirectToRouteResult始终重定向到HTTP GET,asp.net-mvc,redirect,action-filter,Asp.net Mvc,Redirect,Action Filter,我的控制器顶部有一个ActionFilter属性 [HandleError] [MyActionFilter] public class AccountController : Controller { ... } 当收到操作时,我想添加/更改一些路由值,然后重定向到正确的路由 filterContext.Result = new RedirectToRouteResult(new System.Web.Routing.RouteValueDictionary(new { lang = l

我的控制器顶部有一个ActionFilter属性

[HandleError]
[MyActionFilter]
public class AccountController : Controller
{
  ...
}
当收到操作时,我想添加/更改一些路由值,然后重定向到正确的路由

filterContext.Result = new RedirectToRouteResult(new System.Web.Routing.RouteValueDictionary(new { lang = langName, controller = controllerName, action = actionName, id = idName }));
这很好用。但是,重定向总是设置为HTTP GET,并且由于我的一些操作设置为仅接收HTTP POST,因此重定向失败

有没有办法使重定向成为HTTP POST

有没有办法使重定向成为HTTP POST

不,动词GET是HTTP规范中重定向定义的基础。谈论HTTP重定向和与GET不同的HTTP谓词根本没有意义

您可以直接返回视图,而不是重定向:

var result = new ViewResult
{
    ViewName = "~/Views/Shared/SomeView.cshtml",
};
result.Model = new MyViewModel();
filterContext.Result = result;

正如您所说,您正在将用户重定向到另一个操作。在HTTP协议中,这意味着您在响应客户端浏览器的同时发送代码301302、或303

另一方面,浏览器总是发送HTTP Get以响应HTTP重定向

因此,你的答案是:


NoViewResult模型属性仅可用。您可能希望使用result.ViewData.Model