Changing browser URL with Asp.Net MVC and JQuery Mobile

Posted by Goud.Kv under ASP.NET AJAX category on | Points: 40 | Views : 730
Create a Custom Asp.Net Helper like below..,

namespace jQueryMobileSite.CustomHelpers
public static class Custom Asp.Net Helper
public static IHtmlString GetPageUrl(this HtmlHelper htmlHelper, ViewContext viewContext)
StringBuilder urlBuilder = new StringBuilder();
urlBuilder.Append(viewContext.HttpContext.Request.Url.GetComponents (UriComponents.PathAndQuery, UriFormat.UriEscaped));
return htmlHelper.Raw(urlBuilder.ToString());

Now add Custom Helper as below.,

<pages pageBaseType="System.Web.Mvc.WebViewPage">
<!-- other code has been removed for clarity -->
<add namespace="jQueryMobileSite.CustomHelpers"/>

Finally Use that Custom helper in your view as below.,

<div data-role="page" data-theme="d" @Html.GetPageUrl(ViewContext)>
@* TO DO: Your Code *@

Comments or Responses

Login to post response