1:问题描述

  @Url.Action("Index", "Home", new { Key = "Key", Val = new { Name = "TypeDescriptor" } })

   期望结果: /Home/Index?Key=Key&Name=TypeDescriptor

   实际结果: /Home/Index?Key=Key

2.解决方案

  

         /// <summary>
/// 递归算法
/// </summary>
/// <param name="dictionary">dictionary</param>
/// <param name="values">values</param>
public static void GetProperties(RouteValueDictionary dictionary, object values)
{
foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(values))
{
object obj = descriptor.GetValue(values);
if (obj != null)
{
Type type = obj.GetType();
if (!type.IsValueType && type != typeof(string))
{
GetProperties(dictionary, obj);
}
if (type.IsValueType || type == typeof(string))
{
if (dictionary.ContainsKey(descriptor.Name))
{
dictionary[descriptor.Name] = obj;
}
else
{
dictionary.Add(descriptor.Name, obj);
}
}
}
}
}

递归算法获取参数列表

         /// <summary>
/// Action
/// </summary>
/// <param name="urlHelper">urlHelper</param>
/// <param name="actionName">actionName</param>
/// <param name="controllerName">controllerName</param>
/// <param name="routeValues">routeValues</param>
/// <returns>string</returns>
public static string Action(this UrlHelper urlHelper, string actionName, string controllerName, object routeValues)
{
RouteValueDictionary dictionary = new RouteValueDictionary();
GetProperties(dictionary, routeValues);
return UrlHelper.GenerateUrl(null, actionName, controllerName, dictionary, urlHelper.RouteCollection, urlHelper.RequestContext, true);
}

重写Action

最新文章

  1. javascript面向对象系列第四篇——选项卡的实现
  2. js 基础
  3. 23. Can&#39;t connect to X11 window server using &#39;127.0.0.1:0.0&#39; as the value of the DISPLAY variable.解决办法
  4. ASP.NET MVC 网站开发总结(二)——一个或多个文件的异步或同步上传
  5. Oracle执行语句跟踪(2)——使用10046事件实现语句追踪
  6. wing IDE破解方法
  7. struct TABLE_SHARE
  8. jquery ajax 跨域处理
  9. linux安装php5.3
  10. android可扩展自己的定义,运动图像裁剪框
  11. Linux 上搭建 git 的服务器
  12. 51 nod 1394 1394 差和问题(线段树)
  13. 关于ROS学习的一些反思
  14. python模拟登陆Github示例
  15. [转载]关于laravel中表关系的一对一、一对多、多对一、多对多实践
  16. (PMP)第3章-----项目经理的角色
  17. 利用ArcGIS-Server瓦片制作离线地图包(*.tpk)_详细流程
  18. ABBYY FineReader 12使用教程
  19. go语言练习:条件语句和循环语句
  20. 中文解码Unicode

热门文章

  1. 【转】 Oracle 用户权限管理方法
  2. loadrunner获取接口返回参数(包括body,headers等)
  3. excel 批量在一列数据添加单引号以及逗号
  4. Ajax—web中ajax的常用方式
  5. matplotlib显示中文
  6. Detour的简单使用
  7. C++ Word Count 发布程序
  8. java多线程-----volatile
  9. MySQL Crash Course #13# Chapter 21. Creating and Manipulating Tables
  10. 负载均衡之-haproxy