1.获取url中controller和action

第一种:

   获取controller名称:ViewContext.RouteData.Values["controller"]

   获取action名称:ViewContext.RouteData.Values["action"]

第二种:

   ViewContext.Controller.ValueProvider.GetValue("controller").RawValue

   ViewContext.Controller.ValueProvider.GetValue("action").RawValue

 

 

2.遍历路由参数集合

@{
    //路由参数 至少得的两个参数 为 
    //控制器名称和Action名称

    //controller-----RotateDataOne
    //action-----RotateOne

    RouteValueDictionary rotate = this.ViewContext.RouteData.Values;
    
    <p>遍历输出所有的键值:</p>
    
    foreach (var key in rotate.Keys)
    {
    <div>@key-----@rotate[key]</div>
    }
    
    
    <h3>如有记录的参数总数:@this.ViewContext.RouteData.Values.Count
    </h3>
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-23
  • 2021-10-14
  • 2021-09-13
  • 2022-12-23
猜你喜欢
  • 2021-10-09
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
  • 2021-04-01
  • 2021-12-08
相关资源
相似解决方案