andrew4582

RouteValueHelper

Dec 21st, 2011
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.77 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Web.Mvc;
  7. using System.Web.Mvc.Html;
  8. using System.Web.Routing;
  9. using System.Web.Security;
  10.  
  11. public static class RouteValueHelper {
  12.    
  13.     public static RouteValueDictionary AnonymousObjectToHtmlAttributes(object htmlAttributes) {
  14.  
  15.         if(htmlAttributes == null) {
  16.             return null;
  17.         }
  18.  
  19.         RouteValueDictionary routeValueDictionaries = new RouteValueDictionary();
  20.        
  21.         foreach(PropertyDescriptor property in TypeDescriptor.GetProperties(htmlAttributes)) {
  22.             routeValueDictionaries.Add(property.Name,property.GetValue(htmlAttributes));
  23.         }
  24.  
  25.         return routeValueDictionaries;
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment