Keeping track of a page's dropdown selection when navigating through different pages in MVC, C# and AngularJS

When using C#, .Net, MVC5, AngularJS and the Select2 dropdown control, you'll find the dd at the top of the layout for users to select a project. The select2 control can be populated as explained in detail here.

To ensure global data accessibility, a Angular service was created with the following code snippet:

var app = angular.module('app', ['kendo.directives', 'ngResource', 'ngRoute', 'ngSanitize', 'ui.select2']);

    app.factory('globalContainer', function () {
        var globalContainer = {};

        globalContainer.dashboardGlobals = {
            userContext: Object(null),
            currentProject: Object(null),
            projectList: Object(null),
            testString: "Global Test String!!!"
        };

        return globalContainer;
    });

The values are then set in a controller as shown below:

app.controller('projectListController', ['$rootScope', '$scope', '$log', 'abstractDataFactory', 'customUIFunctions', 'globalContainer',
    function ($rootScope, $scope, $log, abstractDataFactory, customUIFunctions, globalContainer) {
        var vm = this;
        vm.dashboardGlobals = globalContainer.dashboardGlobals;
...


  vm.dashboardGlobals.projectList = result.value;
// make a restful call w/ data to set value on server side

However, an issue arises when loading a new page as the values reset. The question of how to maintain these values across pages without the use of a Single Page Application (SPA) is raised.

While considering making a background call to a server controller to populate user context information, the focus remains on finding an Angular-centric solution.

The main goal is to update a globally-accessible client-side object upon changing the DD selection, mirroring the functionality already available on the server side.

Given the current technological stack in place, any suggestions on the best approach would be greatly appreciated.

Please share your insights!

Answer №1

If you're interested in saving data on the browser/client side, check out https://github.com/browserstate/history.js/.

Alternatively, you can send the information back to the server and retrieve it from a model or ViewBag.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The JavaScript function throws an error stating "unlawful return statement"

I am currently working on a task that involves identifying which radio inputs are selected in order to pass that information to my main.js file in Electron. function checkType(){ const types = document.getElementById('type').children; ...

Connect the grid view to the text box by binding the onkeypress event

I currently have a gridview that updates based on the number entered in a textbox using the OnTextChanged event. The issue is that the gridview only refreshes when the textbox loses focus, but I want it to update as soon as a key is pressed while entering ...

Can you provide the regular expression that will reject the character "?"

Can you help me verify that my form does not accept double quotes? Validators.pattern(/^(?!").*/g) The current solution is not functioning properly. I want to allow all characters except for double quotes. ...

Retrieving Data from a Nested JSON Array

How do I modify my JavaScript code to extract the last 3 values from the JSON list provided below? The current code is unable to read these values with different formatting. Example section of the JSON list: {...... 'Design_Lump_Sum': {0: {&a ...

Patience is key when it comes to waiting for a function to finish before moving on to the next step

I'm delving into the world of node js and currently immersing myself in the concepts of promises and async/await. Here's a code snippet I've been experimenting with, but I can't quite figure out how to ensure that the code waits until t ...

Locate the error message for the input field length

I'm struggling to determine the number of errors in $scope.someForm.$error and am having difficulty finding a way to calculate it. Here is an example of $error: $scope.someForm.$error Object{date-disabled: Array[1], required: Array[1]} The expected ...

Why is my jQuery blur function failing to execute?

Currently, I am working with HTML and the jQuery library to avoid core JavaScript in order to maintain consistency. In my project, there are 3 fields and when a user clicks on field1 and then somewhere else, I want only field1's border to turn red. T ...

Transferring ajax data to a variable on a Node.js server

I am currently facing an issue with an ajax get request that involves passing data from an input into a variable and using it in a query. The situation is being handled within index.handlebars page: <!DOCTYPE html> <html> <head> ...

A guide to integrating gatsby-remark-images-grid in markdown with Gatsby.js

Currently, I am working on creating a blog using Gatsby.js with markdown and I want to incorporate CSS grid into my blog posts to showcase a beautiful grid layout of images. I am aware that Gatsby offers incredible plugins to address various challenges. ...

Ways to fill ng-style with a CSS object

Creating a dynamic form to manipulate CSS properties in real time has been my latest project. I've managed to define the CSS property names and values within an object, but now I'm struggling to style the item elegantly on the page as the user in ...

What is the best way to display my apex chart once the ajax request has finished?

I am currently working with the Apex dynamic chart, which can be found here. I'm encountering some difficulties with the ajax call and chart rendering section. The issue arises when I interact with the Country Bar chart. Upon clicking on a country ba ...

Is there an issue with AJAX variables not retrieving data from the PHP file?

In my script, I have a function that is responsible for saving the file. function saveMap() { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xm ...

Utilizing Node.js to import files without the use of namespaces

I am in the process of transitioning a codebase from being entirely browser-based to incorporating both server-side and client-side functionalities. One major challenge I have encountered is the need to use modules in order for my code to run smoothly usi ...

Unable to establish new headers once they have already been established

I am attempting to retrieve the idsFromMongo that I saved in my neo4j database and search for those ids in the mongodb to fetch the desired objects. It successfully works once, but then my server crashes and triggers the error message "Can't set heade ...

Retrieve the element from a nested repeater in Protractor by utilizing the text in the row

Below is the structure of the table I am working with: <table class="table"> <thead> <tr> <th class="checkbox-column"></th> <th class="main-column main-column--checkbox">Name</th> </tr> ...

jQuery does not trigger the error event for a 403 status code when loading a new image src

Currently working on a project that involves implementing a static Google map on a webpage. The challenge I am facing is resizing the map dynamically when the page size changes. In order to achieve this, I have created a function that triggers on page resi ...

How about a fading effect for the select box?

I'm currently working on creating a select tag that opens its options slowly with a fade in, fade out effect when the user clicks on "Actions." I've attempted to use jQuery for this feature but haven't had any luck. Here's my code: &l ...

Tips on displaying five bootstrap modal popups simultaneously on a webpage

I'm looking to achieve a specific functionality that involves opening multiple bootstrap modal popups on one page simultaneously without overlapping each other. Specifically, I need a button to trigger the opening of five separate modals each containi ...

Does Transclude eliminate tr and td elements from the content?

I'm encountering an issue with my angularjs application where the tr and td tags are mysteriously disappearing. angular.module('transcludeExample', []) .directive('pane', function() { return { restrict: 'E' ...

The significance of documenting and optimizing code execution

My coding practice is to always (or at least try to) add comments to my code. However, I have set up my server to delete those comments and extra white space before the final delivery. Should I omit comments from the live system's code (Javascript/php ...