Razor中的ActionLink上的HtmlHelper

时间:2013-11-06 13:20:19

标签: razor actionlink tagbuilder

我使用MVC3 Razor并有一个链接

<a href="@Url.Action("Edit", "Obj", new { id = RSAuth.UserId })" class="gray-butt right">Edit</a>

我写了HtmlHelper

public static MvcHtmlString MyHelper(this HtmlHelper helper, string name, string href, string @class = null)
        {
            var builder = new TagBuilder("a");
            builder.MergeAttribute("href", href);
            builder.AddCssClass(@class);
            builder.InnerHtml = name;
            return new MvcHtmlString(builder.ToString());
        }

这个链接不好

@Html.MyHelper("Edit","@Url.Action('Edit', 'Obj', new { id = RSAuth.UserId })", "gray-butt right")

1 个答案:

答案 0 :(得分:0)

你能试试吗?

@Html.MyHelper("Edit",Url.Action('Edit', 'Obj', new { id = RSAuth.UserId }), "gray-butt right")

删除Url.Action的引用,因为它是一个返回字符串的函数