Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么我的自定义Razor扩展无法正确生成属性?_Razor_Html Helper - Fatal编程技术网

为什么我的自定义Razor扩展无法正确生成属性?

为什么我的自定义Razor扩展无法正确生成属性?,razor,html-helper,Razor,Html Helper,我看到很多问题都在这个问题的边缘徘徊,但不尽相同。我在下面编写了简单的HtmlHelper扩展方法,以创建固定文本为的锚链接。同样,编译器太聪明了,不利于自身: htmlHelper.ActionLink有两个类似的重载: 这导致它改用RouteValueDictionary routeValues,IDictionary HtmlatAttributes方法 <a href="controller/action/id?etc" target="_back">&lt;<

我看到很多问题都在这个问题的边缘徘徊,但不尽相同。我在下面编写了简单的HtmlHelper扩展方法,以创建固定文本为的锚链接。同样,编译器太聪明了,不利于自身:

htmlHelper.ActionLink有两个类似的重载:

这导致它改用RouteValueDictionary routeValues,IDictionary HtmlatAttributes方法

<a href="controller/action/id?etc" target="_back">&lt;</a> 
<a Count="1" Keys="System.Collections.Generic.Dictionary`2+KeyCollection[System.String,System.Object]" Values="System.Collections.Generic.Dictionary`2+ValueCollection[System.String,System.Object]" href="controller/action/id?etc">&lt;</a>"
    public static MvcHtmlString BackLink(this HtmlHelper htmlHelper, string actionName, string controller = null, object routeValuesObject = null, object htmlAttributes = null)
    {
        RouteValueDictionary rvd = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
        rvd.Add("target", "_back");
        return htmlHelper.ActionLink("<", actionName, controller, routeValuesObject, rvd);
    }
    public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, 
           object routeValues, object htmlAttributes);
    public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, 
           RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes);
    public static MvcHtmlString BackLink(this HtmlHelper htmlHelper, string actionName, string controller = null, object routeValuesObject = null, object htmlAttributes = null)
    {
        RouteValueDictionary routeValues = new RouteValueDictionary(routeValuesObject);
        RouteValueDictionary htmlAttr = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
        htmlAttr.Add("target", "_back");
        return htmlHelper.ActionLink("<", actionName, controller, routeValues, htmlAttr);
    }