我使用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")
答案 0 :(得分:0)
你能试试吗?
@Html.MyHelper("Edit",Url.Action('Edit', 'Obj', new { id = RSAuth.UserId }), "gray-butt right")
删除Url.Action的引用,因为它是一个返回字符串的函数