【发布时间】:2015-02-20 04:09:30
【问题描述】:
Razor 中是否有一个方法可以返回当前页面的 URL 而不带查询参数。
我需要把它塞进一个我创建为字符串的 HTML 辅助方法中。
@Url 似乎不起作用,如果我这样做 .ToString() 我只会得到命名空间 LOLLL
剃须刀使用:
<th width="100%" @Html.SortTableClickEvent(@Url.ToString(), "Name")>
HTML 助手:
public static MvcHtmlString SortTableClickEvent(this HtmlHelper html, string url, string column)
{
StringBuilder sortingPropertiesObject = new StringBuilder();
sortingPropertiesObject.Append("var properties = new James.prototype.Table.SortingProperties();");
sortingPropertiesObject.Append("properties.url = \"" + url + "\"");
sortingPropertiesObject.Append("properties.colName = \"" + column + "\"");
string clickEvent = "onclick = James.Table.SortByColumn(properties, this);";
return MvcHtmlString.Create(sortingPropertiesObject + clickEvent);
}
输出到我的 html 的内容:
<th width="100%" onclick='James.Table.SortByColumn("Name",' this);="" properties.colname="Name" james.prototype.table.sortingproperties();properties.url="System.Web.Mvc.UrlHelper" properties="new" var="">
Name
</th>
【问题讨论】:
标签: c# razor visual-studio-2013