Changing browser URL with Asp.Net MVC and JQuery Mobile

Goud.Kv
Posted by Goud.Kv under ASP.NET AJAX category on | Points: 40 | Views : 922
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("data-url='");
urlBuilder.Append(viewContext.HttpContext.Request.Url.GetComponents (UriComponents.PathAndQuery, UriFormat.UriEscaped));
urlBuilder.Append("'");
return htmlHelper.Raw(urlBuilder.ToString());
}
}
}


Now add Custom Helper as below.,

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


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

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

Comments or Responses

Login to post response