aspnet / AspNetWebStack

ASP.NET MVC 5.x, Web API 2.x, and Web Pages 3.x (not ASP.NET Core)
Other
858 stars 354 forks source link

make TypeHelper support IDictionary<string,Object> or RouteValueDictionary #259

Closed sdwdjzhy closed 3 years ago

sdwdjzhy commented 5 years ago

In using HtmlHelper.ActionLink, AjaxHelper.AjaxForm, or other functions that use the route parameter, I find that the route parameter does not support passing IDictionary<string, Object>or RouteValue Dictionary. Additionally, additionalViewData parameter used by HtmlHelper.Editor does not support access to IDictionary<string, Object> or RouteValue Dictionary. I looked at the source code, which should be TypeHelper.ObjectToDictionary

Perhaps you should consider adding the following code

 public static RouteValueDictionary ObjectToDictionary(object value)
        {
            if(value == null)
            {
                return new RouteValueDictionary();
            }
            if(value is RouteValueDictionary)
            {
                return value as RouteValueDictionary;
            }
            if(value is IDictionary<string,object>)
            {
                return new RouteValueDictionary(value as IDictionary<string, object>);
            }

            RouteValueDictionary dictionary = new RouteValueDictionary();

            if (value != null)
            {
                foreach (PropertyHelper helper in PropertyHelper.GetProperties(value))
                {
                    dictionary.Add(helper.Name, helper.GetValue(value));
                }
            }

            return dictionary;
        }
mkArtakMSFT commented 3 years ago

Thanks for contacting us. We're not making any improvements in this area any more as this project is in maintenance mode. Only critical blocking issue with wide impact and security issues are considered.