什么是Routedata.Values​​ [""] [英] What is Routedata.Values[""]?

查看:273
本文介绍了什么是Routedata.Values​​ [""]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很惊讶地看到,没有文章,回答与任何细节这个问题。我有关于 RouteData.Values​​几个问题[]

I am surprised to see that there is no article which answers this question with any details. I have few questions related to RouteData.Values[""].

我看到这个code:

public ActionResult Index()
{
    ViewBag.Message = string.Format("{0}---{1}--{2}",
        RouteData.Values["Controller"],
        RouteData.Values["action"],
        RouteData.Values["id"]);

    return View();
}

这基本上是看完这可能听起来像控制器的元数据的价值观。或者是它的东西,查看也可以传递给控制器​​?

Here it is basically reading values which potentially sounds like "Meta-data" of the controller. Or is it something that View can also pass to Controller?

推荐答案

RouteData.Values​​用于访问通过处理路由类插入的值/查询字符串值。

在你的情况,在你的路由配置类中定义的路径有哪些会被提供的参数附加参数。

该参数是控制器,动作ID。

这些参数的参数会一直在你的code某处提供。

RouteData.Values is used for accessing the values/querystring values inserted by the classes handling routing.
In your case, the route defined in your route configuration class has additional parameters to which arguments would have been provided.
The parameters are controller, action, id.
The arguments to these parameters would have been provided somewhere in your code.

它更有意义,当你开始几级高,所以你知道你要搜索的内容。


  1. 在Global.asax.cs中

  1. The Global.asax.cs

protected void Application_Start(object sender, EventArgs e)
{
    routingActions.RegisterCustomRoutes(RouteTable.Routes);
}


  • 另外一个类定义了上述方法:

  • Another class defines the above method:

    public void RegisterCustomRoutes(RouteCollection routes)
    {
        routes.MapPageRoute("searchdetails", "searchdetails/{orderID}/{PageIndex}/{PageSize}", "~/View/SearchDetails.aspx");
    }
    


  • 以下code创建超链接。主要的区别是被构造中的HREF的方式。
    在这种情况下,searchdetails中包含自己的路由配置中的类定义

  • The following code creates a hyperlink. The main difference is the way the HREF is constructed. In this case, the "searchdetails" is defined in the class which contains my route configuration.

    linkToDetails.HRef = GetRouteUrl("searchdetails",
                    new
                    {
                        orderID = someOrderID,
                        PageIndex = currentPageIndex,
                        PageSize = PageSize
                    });
    


  • 最后,目标页面需要使用在第3步传递这一信息。
    这是我们使用 RouteData.Values​​ []

    protected void Page_Load(object sender, EventArgs e)
    {
        var _orderid = Page.RouteData.Values["orderID"].ToString();
        var _PageIndex = Convert.ToInt32(Page.RouteData.Values["PageIndex"]);
        var _PageSize = Convert.ToInt32(Page.RouteData.Values["PageSize"]);
    }
    


  • 这篇关于什么是Routedata.Values​​ [""]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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