获取无查询参数当前页面的URL - 剃刀的HTML帮助? [英] Get current page URL without query parameters - Razor Html helper?

查看:161
本文介绍了获取无查询参数当前页面的URL - 剃刀的HTML帮助?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有剃刀的方法返回没有查询参数的当前页面的URL。



我需要把它推到我已经作为一个创建的HTML辅助方法,字符串。



@url 似乎并没有工作,如果我这样做的ToString( )我刚刚得到的命名空间LOLLL



剃须刀使用:

 百分位宽度=100%@ Html.SortTableClickEvent(@ Url.ToString(),姓名)> 



的HTML帮助:



 公共静态MvcHtmlString SortTableClickEvent(这个HTML的HtmlHelper,URL字符串,字符串列)
{
StringBuilder的sortingPropertiesObject =新的StringBuilder();
sortingPropertiesObject.Append(VAR性能=新James.prototype.Table.SortingProperties(););
sortingPropertiesObject.Append(properties.url = \+ URL +\);
sortingPropertiesObject.Append(properties.colName = \+列+\);

串clickEvent =的onclick = James.Table.SortByColumn(属性,这一点);

返回MvcHtmlString.Create(sortingPropertiesObject + clickEvent);
}



输出,怎么得到我的HTML:

 百分位宽度=100%的onclick ='James.Table.SortByColumn(姓名,这一点); = properties.colname =名称james.prototype.table.sortingproperties(); properties.url =System.Web.Mvc.UrlHelper性能=新VAR => 
名称
< /第i


解决方案

您可以使用请求。 Url.GetLeftPart 方法的。如果您的网址是说

  http://the-site.com/controller/action?param=1 

执行 Request.Url.GetLeftPart(UriPartial.Path)应给

  http://the-site.com/controller/action 

在代码中可能看起来是这样的:

 < ;日WIDTH =100%@ Html.SortTableClickEvent(@ Request.Url.GetLeftPart(UriPartial.Path),姓名)> 


Is there a method in Razor that returns the current pages URL without the query parameters.

I need to shove it into an HTML helper method I have created as a string.

@Url does not seem to work and if I do .ToString() I just get the namespace LOLLL

Razor use:

<th width="100%" @Html.SortTableClickEvent(@Url.ToString(), "Name")>

Html helper:

    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);
    }

What gets output to my 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>

解决方案

You can use Request.Url.GetLeftPart method for that. If your URL is say

http://the-site.com/controller/action?param=1

executing Request.Url.GetLeftPart(UriPartial.Path) should give

http://the-site.com/controller/action

In code that might look like this:

<th width="100%" @Html.SortTableClickEvent(@Request.Url.GetLeftPart(UriPartial.Path), "Name")>

这篇关于获取无查询参数当前页面的URL - 剃刀的HTML帮助?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆