我怎样才能从我的ActionExecuting过滤器内部获取路线值? [英] How can I get route values from inside my ActionExecuting filter?

查看:218
本文介绍了我怎样才能从我的ActionExecuting过滤器内部获取路线值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能从我的 OnActionExecuting 过滤方法内部路由值。

How can I get route values from inside my OnActionExecuting filter method.

我有以下两个建议,但我仍然感到困惑:

I had the following two suggestions but I am still confused:


    在方法
  1. 访问你的 ControllerContext ,并且可以访问 RouteValues​​ 所以 filterContext .Controller.RouteValues​​

  2. 访问 filterContext.Controller.RouteValues​​

  1. Access your ControllerContext in the method and that gives you access to RouteValues so filterContext.Controller.RouteValues
  2. Access filterContext.Controller.RouteValues

我有例如方法:

public ActionResult Delete(string city, string street) {
    //enter code here
}

如果我想要得到的城市和街道的值,那么我怎么能做到这一点。如果它看起来像对不起一个基本的问题,但我不知道如何访问上面的。

If I want to get the value of city and street then how can I do this. Sorry if it seems like a basic question but I am not sure how to get access to the above.

推荐答案

这是

    protected override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        var parameters = filterContext.ActionParameters;
        var email = parameters["email"];
        var city = parameters["city"];
    }

这篇关于我怎样才能从我的ActionExecuting过滤器内部获取路线值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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