1

I'm building an ASP.NET MVC 4 website that needs to be available offline (HTML 5 manifests/caching), so I will be unable to take advantage of server side HTML generation.

Right now, I just have generic/cacheable HTML on the View (.cshtml) and I'm making jQuery AJAX calls on document ready to load the data from the server and using mustache.js to generate the HTML.

Being constrained to doing HTML generation only in the client side, I'm unable to use Url.RouteUrl to generate links and also constrained to having to parse the current URL manually when navigating to a details page, and using the Id (or whatever the parameter is) to make the AJAX call to retrieve the information for the specific record that I need.

Since I'm still using MVC URL Routing (and would like to keep using it) to return the corresponding View (as in, http://localhost:27954/Route/Test2/7?mytext=hellow), I'll need a javascript or jQuery function to both be able to parse URL's and retrieve the value for a given querystring parameter, and ideally another method to generate URLs.

Since I'm obviously not the first person in this situation, I was wondering if anyone had any proven methods already that they could share, or any recommendations.

Thanks!

GR7
  • 5,083
  • 8
  • 48
  • 66
  • I don't know how much it might help, but I do have a jQuery Plugin that is similar to "RouteURL". It's closer in resemblance to a base_url type method in PHP, but it's all jQuery. [It's at this fiddle, along with alot of examples on usage](http://fiddle.jshell.net/2ZuTe/). A basic example is `$.myURL()` used on this page would return a *string* of `http://stackoverflow.com/questions/`. Some more: `$.myURL("home", "dir")` = `http://stackoverflow.com/questions/home/dir` : `$.myURL("pathname")` = `/questions/16423095/javascript-or-jquery-method-to-parse-asp-net-mvc-route-url` – SpYk3HH May 07 '13 at 15:49
  • $.myURL("afterpath") would help get parameters in which you can use something like [this](http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values) to get an array of params (i plan on adding option for that one day). Caution, this was originally designed for use with PHP sites, thus `$.myURL("index")` automatically returns `http://stackoverflow.com/questions/index.php'. However, that's only if "index" is the first para and the only word in the string. Thus `$.myURL("index.asp")` would return `http://stackoverflow.com/questions/index.asp' – SpYk3HH May 07 '13 at 15:51
  • SO Question: [How can I get query string values?](http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values) – SpYk3HH May 07 '13 at 15:55

0 Answers0