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")>
                        Without querystring:
Request.Url.GetLeftPart(UriPartial.Path)
With querystring
Request.Url.PathAndQuery
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With