I am having a button that is placed in _layout.cshtml as i want to be seen on each and every view.
Based on the click of the next button i want to navigate through various views i have created.
Please reply as it is urgent and i am new to MVC 3.
Thanks in advance.
Using a variable in session to track the current view you could have a button which when clicked went to the next view in a list of views when compared to the current view in the session where the view was a partial view. However, this approach defeats the purpose of decoupling and MVC in general.
Related
I have a ASP.Net Core MVC web application. I have a standard razor view which has a list of items with a delete button. What I want to do is if they user deletes an item from the grid go to the server calling an action which validates the item selected. IF invalid I want to return to the view and show a bootstrap modal explaining why the delete cannot be carried out. I call the delete routine using Controller / Action tag helpers and pass the unique Id to a controller event.
So basically if my delete validation fails show a modal dialog with a message. Any help please?
I ended up sorting this myself. Basically I set a viewbag property and give it a value of show. Then in my script section of my view I set the modal property to that viewbag.
To design views that each jsp views have common navigation menu ( a treetable, when clicking on a tree node it navigates to another page) what is a good approach for this?
Adding a new node to navigation menu will effect all pages.
Navigation menu tree nodes will be populated from db (a menu table on db)
Is it possible to cache menu view on client so navigation menu will not be populated each time user navigates another page?
Thank you
There are two separate questions asked in the post, I will answer them accordingly:
1) I would recommend using a Template Engine which integrates with JSPs.
Apache Tiles fits in this category. Using this framework, you can define template which contains common sections for header, footer, body and menu layouts. Furthermore, it supports derived templates via inheritance.
2) Caching solution : Since you want to load values from database to make the menu dynamic, caching and pre-populating the menu will minimize page load times. This should be done on server side.
A separate thread/process should be made responsible for pre-populating and refreshing cache periodically.
From clean code perspective, JSP or Tiles template should not invoke database calls. Instead the page should interact with a DAO/component to separate concerns and ensure MVC pattern is not broken.
Helpful links:
Tiles Example
Thymeleaf - an alternative to Tiles
My team is creating an MVC4 application which has an upper menu structure that contains menu items specific for the currently logged-in user, and displays the content for the selected menu item below. The menus are displayed in a partial view "_MainMenu" and the MainMenuController Index action is responsible for getting the menu data from the database and returning the menu partial view. The main layout "_Layout" renders the menu by calling #Html.Action("Index", "MainMenu").
We want to avoid hitting the database to get the menu structure data every time the page is refreshed, and we also ideally want to avoid any visible reload of the menu structure when a different menu item is selected.
I've been looking into AJAX, and I've implemented something where selecting a new menu item will load the content for that item below the menu by replacing a div with ID="mainContent" with the content as a partial view (this div lives on the loaded view "MainContent"). In this way, the menu is never re-loaded and the page never refreshes completely (only the different partial content views are swapped in and out as different menu items are selected).
This solution works, but I'm not sure if it's really best practice, or if there's a better solution involving caching. One of the problems with the AJAX solution is the URL never changes from "http://MySite/MainContent". This means that clicking the Back button on the browser doesn't work as expected, and also hitting F5 to refresh the browser page loses the currently displayed page. The refresh issue can probably be resolved by remembering the selected menu item, but I'm still not convinced this isthe way AJAX was intended to be used.
Can someone please tell me if they think caching would be a better solution for this scenario based on their experience.
If the user's menu items are not likely to change, then you could use a simple static Dictionary (the long is the user id) to cache the data in the backend, and refresh it periodically.
Generally, if you do any caching you have to make sure the cached data gets refreshed when underlying data is updated. Therefore it's only simple and safe if you have only one app accessing your DB. If there are multiple apps, then you'll have to add a mechanism to keep the cache in sync.
In project I'm working on we've stored User-Role-Module entities and relationships in DB, and bound module permissions to roles rather than users. Since role permissions aren't likely to change, they're safe to cache.
I am new to MVC3. In asp.net user control, its fairly easy to create a user control that has a combo box with a button, with hover over event, and a collection property of combo box that then displays a list
how do i achieve this user control (partial view) in mvc3?
What you are looking for is helper methods. You can see a good explanation of it here. In that post, there is a great link for how to do this: Creating Custom HTML Helpers.
I am also a WebForms developer originally, and I had a hard time making the connection between user controls and HTML Helpers. This should give you enough guidance to get started with what you want.
Hover over event can be done using jQuery, your combo box just needs to have a CSS class in the partial view and then the even can be hooked up to that selector.
The Collection property will be inside the View Model that your partial view binds to.
I used .Net's dynamic data entity to implement a website that sits on top of my db (see
http://msdn.microsoft.com/en-us/library/ee845452.aspx)
In the List.aspx-View for a table, I am able to sort/filter the data of the gridview. After having clicked on a row's 'Details' link, I would like to provide the user a 'Back' button in the Details-View that navigates the user back to exactly the same filtered/sorted table.
So far, all sorting and filtering information is lost when navigating back to List.aspx.
Any ideas how to implement this feature? Do I need to work with ViewState?
Thanks a lot
Cheers
Chris
have a look at my article here
AJAX History in a Dynamic Data Website this works when using the back button in the browser to navigate back to the List page.