How to make the current child page refresh from the master page of an MVC app - asp.net-mvc

I'm developing an MVC application that is essentially a "dashboard" on the home page and the rest of the application is various reports. One of the requirements is to be able to change parameters in the header that affect whatever page you are on. For example, if you are on the home page and looking at data for Group A, you can change to Group B and see the dashboard change. Similar behavior if you are on a report page - change to Group C, and the report refreshes with the appropriate data.
The listing of groups is a dynamically created menu in the master page, so each group option is a link. Normally I'd make each link an ActionLink and direct it to a specific page, but in this case I need the link to write the selection to a database and tell whatever the child page is to refresh.
What's the correct/most efficient/best way to set this up?

I'd consider doing this with a tabbed interface using jQuery UI tabs. In this case each tab corresponds to the action that generates the dashboard for a group. Switching between tabs causes the action for the tab to reload via AJAX the tab's contents. You can use the Cookie plugin to make the tab sticky between sessions -- see the docs for the tabs plugin.

Related

Multiple actions on click - ordering issue

When the user clicks on a link to a subpage, I want to store data in sessionStorage from the current page before leaving to the next page. Then when this new page has loaded, I want to apply the sessionStorage data on this page.
What complicates things is that the link is part a collapsing menu system. Which means that this system needs to update (which is also done on click) before the page data is stored.
So essentially, the wanted execution order:
User clicks link
Menu system is updated
Page data is stored
Browser loads the new page
Page data from the previous page loads and applies on the new page
My issue is the order in which everything is executed. I don't understand when the user clicks on the link how to control the order of when the actions are executed.
Thankful for help

Handling the back button while using multi step remote links

I have a 3 step report which loads by clicking a link with the remote: :true option, so it reloads a part of the page instead of refreshing the whole page. I also provide the user with breadcrumbs, so he/she can easily navigate between the steps. However, most users use the browser back button, which of course reloads the whole page. What is the "Rails way" of dealing with this? If the browser back button is clicked the user should see the previous step in the report.
If you need to control the history the user sees, but aren't doing full page reloads on form submit, you should be manipulating the history state via Javascript's history.pushState and friends.
Assuming the responds to the submitted form is some sort of evaluated Javascript, simply include the history state manipulations there.

Durandal+Knockout to develop a Single Page Application: Selectively show portions of page based upon authorization

I am using Durandal, knockout to create a Single Page Application. I need to do following (two pretty simple things):
Show/hide widgets that are only for administrator, based upon the user's authorization,
Change menu options based upon whether user is authenticated or not (for anonymous show - login/sign up and when authenticated show "Welcome .." .
If this was a regular MVC4 application I would have done it using
#if (User.Identity.IsAuthenticated) { ... } check in razor views, but with views in durandal this is ruled out.
I want to avoid putting sensitive business logic in javascript - user need not know what kind of options could have been available to him if he was an administrator.
What's the best way to achieve this in Durandal & Knockout? I have been coding so far using classic ASP.NET and lately using ASP.NET MVC. Developing SPA using Durandal is a new game for me...If anyone can give me only steps/pointers to do this that will help a lot too..thanks in advance!
The way I do it.
My menus are build inside a menubar.js file. The menuItems are observableArrays([]) initially and I subscribe to a topic "user-logged-in".
When the user logs in, I get the user's permissions/roles and store them locally in storage. and then send out notification "user-logged-in" with the user data.
My menubar recieves the notification, checks the permissions/roles and adds various menu items appropriately.
the shell.html has a view composition for the menubar.js. So if there are menuitems, it shows up, else it does not. so when the user logs in, the menuItems are populated and at this point the menu items show up.
When the user logs out, I clear the local storage cache and send out a message "user-logged-out".
The menubar.js recieves this message and clears it's menu items, essentially clearing the menu on the menubar.htm
You can essentially do the same for the widgets and use a visible binding to a property which hides or shows for a particular permission/role.
Also important is router.guardRoute. read up on this so that people cannot directly go to a route without logging in.
Hope that helps

load layout page only once in mvc 4 asp .net razor

hi i have mvc website where i am using layout for consistant look and feel. now my menu is dynamically generated based on user role,level etc. i have put menu on layout page.when user logs in menu generated as per its role from database .when user clicks on menu it loads the currosponding view in layout, but it also refresh the layout page becouse all views have layout , so menu also gets regenerated cousing databse trip. how should i avoid menu reloading ? i dont want to use ajax to load views in layout page becouse back button doesent work and new tab loads pages without layout. please help
what i did is loded the pages without layout in div inside layout using ajax.and
in viewstart.chtml
written following
Layout = Request.IsAjaxRequest() ? null : "~/Views/Shared/_Layout.cshtml";
so when request is through link (in new window) views will come with layout page (this solved new tab problem).
2) for backbutton of browser used jquery.address plugin.
A common use for session variables is to store the user, and its role, level, etc. This may or may not avoid a DB round trip, depending on where you store your session. For example, an "InProc" session state (the default) is stored in memory, so access is very fast). See: Which one is better, InProc or SQL Server, for Session State mode in asp.net?

already logged page should be display when open new tab in struts2

I developing Struts2 project.
In that project the user can log in and do something its work fine.
If that user open the new tab and type my project url it will show the same page(after login page).
How do I implement the above scenario?
One way would be doing like described here, in a question almost identical to your (concept is the same, only the implementation, on .NET, differs).
Calculate an unique value each time you pass in the Action, then put
it in a session variable (that is server side) and use it to feed an
hidden field on the web page (that is client side).
When the page will post back (submit) the form containing your hidden field, you
will see if the page field and the session field are the same.
If yes: it is (the only OR) the last page / tab opened.
If no: you are trying to submit the form from a page that is not the
last page opened.
This way, you will always have only one instance of the web application, and if you open another instance of the web application in a new page / tab, it will invalidate the previous one: only the last opened will be valid (because of multiple hidden fields, one for each page, but only one session variable).
IF you really need (do you?) to prevent the user opening a new tab instead of ensuring a single instance for the web-app, start working from this principle and eventually come back here (better with some code)

Resources