Single page application vs Standard MVC more details in post - asp.net-mvc

I'm using kendo for my client side framework using MVVM single page application architecture for a multi page MVC app that I'm currently working on. What happens is there are 4 pages/steps in total in which the first 3 steps requires users to enter in some information and hitting the next button and using kendos router function to route to the specific page on button "Next" press.
Each pages values depends on the previous page, so in page 1 user would enter in some user ID's, on next button click it will call an AJAX call to my controller method passing in a viewmodel from the view and then returning some values based on those ID's and load them on page 2.
Because the values are loaded based on a kendo observable viewmodel from the view on page 1, if the user was to refresh on page 2, the values would all become null since the refresh would basically wipe out all the values saved in the viewmodel or if the user presses the "Previous" button or the back button on the browser whatever values they entered on page 1 would also be empty instead of displaying the previous values they've entered.
Main question would be is this the right architecture for what I'm doing? Should I just be doing standard MVC and passing my viewmodels/populating my screens from the server side so my values would never be null but on refresh it would just always hit the server side code.
If a single page application architecture is fine for such an application what would be some solutions for this problem?
Thanks

Related

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)

C# MVC Create Form

I am using C# MVC. I have created a forms before where all of the data needed is on one form. Once the user fills, it then goes to the controller which inserts the data into a database table.
How would I handle a situation where the fields are on 3 different pages. On the 3 page, I like to submit. How does the data presist?
Also is a session variable Ok to use for data that is shared with many pages?
You could use different views, or use one view with a tabbed UI, and use three partial views as the content for each tab as an alternative.
You can use session, but then you have to ensure they can complete the content within the 20 minute time limit; as long as a postback occurs, then that limit is reset.
If your doing a wizard style workflow you could just have a ViewModel for each page and as the user progresses through to each page store each ViewModel in a Session variable. Then upon complete you could grab all the Models out of Session then aggregate the values into your completed form state.
Another way would be, for each POST call service that persists the page data into a data store so as the user navigates through each page, the entity is populated and stored on your data base via some service.
Could just have one partial view to spit out one single ViewModel that has properties for all 3 pages, and then use jQuery wizard plugins (or maybe you're writing your own) to simple manipulate the DOM to show/hide each page as the NEXT/PREVIOUS buttons are clicked. It will all still be part of one single FORM. And then hitting submit would post back to your controller method, say with a $.ajax() POST with serialized JSON.
If you shared a view model between all 3 of the pages in the Wizard, you could deploy HiddenFor fields on the pages to retain information that is not visible on that page of the Wizard.
This would persist data fields entered on other forms throughout your wizard and does not rely on the Session to store the information.

ASP.NET MVC 3 Session

I am very new to MVC. I am coming from web forms.
I have a simple search page. The user has option of searching contacts by state. I have a multi select box where they can select multiple states and click search contacts.
The result contacts will be displayed in a grid. The grid has options of edit,details and delete.
When they click delete it goes to a different page and asks for confirmation. Once they click delete and its done succesfully i am redirecting to the search page. But i want to redirect them to the same list they have earlier.
How i can acheive this with MVC ??
I am storing the selected state ids in an integer array in the view model.
You could try doing a modal popup and then doing an Ajax request and bind the results to a Partial view on the page.
Ie. $('#partialDiv').load( your controller call here )
Might make for a better experience...

How to persist a model across multiple requests in ASP.NET MVC 2

I'm building a web application that has a particular model representing some events. Users need to be able to add N number of people to a given event. Choosing people is handled by a partial view.
I'm trying to build a menu that displays when users click "add a person" to the event. Because the event hasn't been filled out completely yet, there is nothing in the database to persist between requests.
I also have validation logic on the event page.
My proposed solution is to add the form to search or add for people on the event form itself and have a submit button that sends the values that have been added back to the server, where I can store them in ViewData or Session.
Unfortunately, doing this flags the validation.
My second solution is to load a partial view responsible for loading the UI to add/search for a person. I could add a little code on the method in the controller that returns a partial view storing the existing data in a session variable or viewdata. Trouble is, I have to submit the form to do it--again tripping the validation!!!
I'm wondering if perhaps I chose the wrong tool to do this...because in webforms, there would probably be a postback and you would just perform an operation on that postback. I'd like to avoid rewriting the application in webforms and am wondering if there are ways I'm overlooking in ASP.NET MVC.
Thanks in advance for the ideas!
I would probably have the partial view send it's data to the main page (with javascript). That way there is only one post to the server and it is when all of the data the user needs to enter has been filled out. How are you displaying the partial view? Is it on the main page (in a div), or is it a separate pop-up window? Either way, you should be able to use javascript to store this data on the main page and post all of the data back at one time.
HTH

Parameters through postback

I'm working with Ruby on rails 2.3.4 and I'd like to pass some parameters from one page to another ones the first one is submitted.
For example:
On the first page, I have a form that when it's filled a Preview button can be clicked to check all the info entered before submitting the form. That button redirects to another page with the info entered before, but I don't know how to get it in the second page.
There are two possible solutions:
You can emulate the stepped form filling by creating a record in first form and saving it with status "unverified" or "pending". This way you won't have to deal with hidden form fields in 2nd and 3rd pages. All you'll need to pass is the id of pending record. You'll just need to update record status to "active" once the data is confirmed.
Use client side paginated from (all popular JS frameworks have plugins for this). Hence you will only display different <div>s in single loaded page (something like an interface for a setup wizard).

Resources