Jim*_*988 14 c# razor visual-studio-2013
Razor中是否有一个方法返回当前页面URL而不使用查询参数.
我需要把它推到我作为字符串创建的HTML帮助器方法中.
@Url
似乎不起作用,如果我这样做,.ToString()
我只是得到名称空间LOLLL
剃刀使用:
<th width="100%" @Html.SortTableClickEvent(@Url.ToString(), "Name")>
Run Code Online (Sandbox Code Playgroud)
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);
}
Run Code Online (Sandbox Code Playgroud)
什么输出到我的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>
Run Code Online (Sandbox Code Playgroud)
And*_*rei 25
你可以使用Request.Url.GetLeftPart
方法.如果您的网址是说
http://the-site.com/controller/action?param=1
Run Code Online (Sandbox Code Playgroud)
执行Request.Url.GetLeftPart(UriPartial.Path)
应该给
http://the-site.com/controller/action
Run Code Online (Sandbox Code Playgroud)
在可能如下所示的代码中:
<th width="100%" @Html.SortTableClickEvent(@Request.Url.GetLeftPart(UriPartial.Path), "Name")>
Run Code Online (Sandbox Code Playgroud)
没有查询字符串:
Request.Url.GetLeftPart(UriPartial.Path)
Run Code Online (Sandbox Code Playgroud)
使用查询字符串
Request.Url.PathAndQuery
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
27453 次 |
最近记录: |