jeudi 11 juin 2015

What is the best practice for maintain a menu after a page reload? I have this custom code which feels wrong

I have a custom Menu which loads a new MVC View for each click as I want. I load the new View by setting window.location.href. To make it work I have to set the baseURL (the name of the website) each time. To Store the state of the menu I use URL's querystring.

My concerns is in the use of:

  1. '/WebConsole53/' // hardcode baseurl i have to apply each time manually
  2. Setting window.location.href to load the new View from JavaScript // Is this the best way or should I use some URL/Html helpers instead?
  3. I store the state of the selected menuItem in the querystring ("menu") // Is it more common to store that kind in Session/Cookie?

Any thoughts, corrections and suggestions would be much appriciated - thanks.


var controller = $'webconsole-controller');
var action = $'webconsole-action');
var menu = "?menu=" + $self.attr('id');
var relUrl = controller + "/" + action + menu;
var url = urlHelper.getUrl(relUrl);
window.location.href = url;


var urlHelper = function () {
    var getBaseUrl = '/WebConsole53/',

        buildUrl = function(relUrl) {
            return getBaseUrl + relUrl;

    var getUrl = function(relUrl) { // relUrl format: 'controller/action'
        return buildUrl(relUrl);

    return {
        getUrl: getUrl

I Use MVC 5.

Aucun commentaire:

Enregistrer un commentaire