regex - Remove unwanted characters from URL -
i have used getrouteurl create seo friendly urls want remove %20 ie spaces , replace dash ("-"). example page website shown below. want title variable "madonna-item" , not "madonna%20item".
/productsbydepartment/gracya/madonna/madonna%20item?categoryid=9&productid=8&departmentid=4
i have create class (stringhelpers) fix url don't know call fixurl
public static class stringhelpers { public static string fixurl(this string url) { string encodedurl = (url ?? "").tolower(); encodedurl = regex.replace(encodedurl, @"\+", "and"); encodedurl = encodedurl.replace("'", ""); encodedurl = regex.replace(encodedurl, @"[^a-z0-9]", "-"); return encodedurl; }
}
the code contains link update below. want use fixurl on title field, not work.
please can advise me how use fixurl?
<td class="product_title" height="20px" width="180px"> <a href='<%#: getrouteurl("productextraroute", new {categoryid = eval("catid"), productid = eval("productid"), departmentid = eval("depid"), title = eval("title")}).fixurl()%>' class="product"> <asp:literal id="literal2" runat="server" text='<%# eval(("title").fixurl()) %>'></asp:literal>
try decodeuricomponent check http://www.w3schools.com/jsref/jsref_decodeuricomponent.asp
after replace speces -
Comments
Post a Comment