data submission during form submission - asp.net-mvc

i have a form which has two textboxes and a submit button.
on entering data and submitting data gets stored in the database.but if i again refresh the page the same data again gets stored.
How should this be prevented?

One way to solve this common problem is to redirect to another ActionResult, where you inform of the success/failure of the form submission.
Also, try to submit a ViewModel instance (see strongly typed views), not form values. That simplifies data validation.

You should implement a PRG redirect to a confirmation / thank you page.

Related

Is it possible to let a user fill a google form in different sessions?

I want a form where the user can fill some values and then exit, and then come back in some time and complete the form and submit it. Is it possible with google forms? If so, will the data entered in the second session be saved along with the corresponding row in the spreadsheet or will a new row be entered?I hope my question is clear
Data from the Form only goes to the server when it is submitted, so you cannot store that form data before submission (disregarding any data that might have gotten stored in the browser session).
What you could do instead is select Settings and check the option Edit after submit. This way, a user can submit the Form and then come back later to edit the responses.
Reference:
Google Forms: Allow people to edit responses

One view having multiple button in asp.net mvc

I am not able to understand the flow on this page
how they are doing in MVC http://demo.nopcommerce.com/onepagecheckout
till now i created only one button for one page (view ) or provide me some similar link or similar code so i can understand
i want to implement same in my application
Thanks in Advance
The page is using AJAX to achieve the effect. Let's go through how it works.
The page is divided up into four sections.
Billing Address
Payment Method
Payment Information
Confirm Order
Each section is treated separately and are likely rendered using partial views. Each section has it's own form. When the user fills out a section and then submits that section, the form is submitted to a particular action. The Billing Address section submits its form to /checkout/OpcSaveBilling, the Payment Method section submits its form to /checkout/OpcSavePaymentMethod and so on.
When these forms are submitted (asynchronously, remember), the server handles the business logic and the validation and returns a result in the form of JSON. The JSON describes what happened, i.e. the result of the validation (success or fail), any errors that occurred and also contains HTML that the page can use to redisplay that particular section.
How is this data being remembered? Sessions. When forms are successful in their submission, the form data is stored per user in the session data. This way the system knows each user's settings and also knows where they are up to in the process.
The final step, Confirm Order, doesn't bother sending any form data because the server already knows everything through the session information.

Reset Struts2 Token?

I have a token interceptor to block double submitting a form which works great, but I'm looking to reset the token under circumstances.
Essentially what I've got in the page is a list of criteria and a submit button. When the user clicks the submit button, the criteria is stored as a new row in a specific table in the database. An ajax call updates the div underneath the form with a succeeded or failed message. The token works in that I don't want the user attempting to add duplicate rows. However, if you user changes the criteria (either by choosing a different option in a drop-down menu or editing the text in s:textfield) I want it to reset the token to allow form submission again. Currently the user has to go back and fill out a new form which is somewhat inconvenient.
I'm using the standard s:token in the .jsp and interceptor lines in struts.xml. I've been searching for something to reset the token but I haven't found anything. Thanks.
The token is a value in session under "struts.token" and in the form as "struts.token.name".
Since you're making an Ajax request underneath the easiest would likely be to set the session token to whatever is already in the form, or to create your own token interceptor (it's quite short, although it uses a static TokenHelper class, which is unfortunate–noted and logged as something to do) that changes the definition of "multiple" submit. (Hash of form vals? Not sure, never given this much thought.)
I couldn't find any answers on google and I don't appear to be getting any answers here so what I did is created a new button called "Clear Form" which calls some javascript to refresh the page and therefore resetting the token and the forms. Not the most elegant but it works.

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

Rails: GoogleDocs-Style Autosave

I'm trying to build a Rails app in which you can edit the same model from several different locations on the page. I want changes to be saved automatically every X seconds, with an option of manually triggering a save.
I have come up with a solution, but it seems very complicated, and I assume other Rails users have already faced similar questions.
The solution I came up with, is to have a hidden form on my page that is the one actually submitted, and then have multiple "dummy" forms scattered around the page that update the hidden form.
Once submitted, the hidden form updates the model, and the model contains logic to determine which RJS files should be returned in response. These are bundled up and sent as an update response.
some limitations:
Can't wrap the whole page in one form tag (there are multiple models/controllers on the page)
The same field might be editable from multiple locations
Anyone have a more efficient way?
create as much form as you need in your page even of the same instance of the same model
triggering the update would be either a javascript setInterval call, or onblur on your form fields.
your controller should be a REST one, and it will return success or error messages in json variables and a HTTP status (200, 422)
Forget rjs, think client side. Each form in your page will be submitting the form to the update method of your controller. The javascript submitting the form will have a error or success callback which will then show the success or error messages. The idea is that the javascript sending the form "knows" which form it is currently submitting, and it should be able to show error or success by itself dependending of the form it is submitting, it's not the controller job.
Saving the whole page is just serializing all the fields from all the forms and sending it to the update method. (see serialize)

Resources