0

When purchasing a course, the user can enter 1 or more students to register for the course. By default there is only one entry but the user can use a dropdown to select more and then the form will update to show more.

I am accomplishing this by triggering an event when the user changes the dropdown value that uses ajax to call an action which returns a partial with the appropriate number of entries and then I just replace the existing div with the new one.

My question is whether there is a way to implement this so that it's kind of like "refreshing" the page where the form remembers and automatically refills in he values the user already entered just like if you were to refresh the entire webpage. Is there a way to do this, or will I need to pass in the existing values into the action in my ajax call and have the partial set them?

A secondary question I just thought of (and perhaps this should be in another post but I will go ahead and put it here for now) is whether I should be concerned about any weird behavior with validation when doing it this way? (I'm using stock, built in validation with annotations).

BVernon
  • 3,205
  • 5
  • 28
  • 64
  • 1
    We need to at least see the outline of your code to understand what your trying to so. –  Jan 21 '18 at 00:05
  • Hello again @StephenMuecke! This is actually a sort of continuation of the issue you helped me with the other day. I hope this question is not a bad fit for this forum... but in this case I'm trying to find out whether something is possible before I write the code. That is, I don't have the code finished yet to show you. But I am really just wanting to know one thing: is it possible to replace a div using ajax and have the fields in the div be replaced with the values that were there before similar to how the web page does when you refresh the whole page. – BVernon Jan 21 '18 at 00:25
  • I think the answer is no but I didn't want to assume. – BVernon Jan 21 '18 at 00:26
  • Yes its possible, but its not really clear what your wanting to do (and it sounds as if your not going about it the right way anyway) –  Jan 21 '18 at 00:31
  • For example, if you wanting to dynamically add items to a collection, then refer [here](http://stackoverflow.com/questions/28019793/submit-same-partial-view-called-multiple-times-data-to-controller/28081308#28081308) and [here](http://stackoverflow.com/questions/40539321/partial-view-passing-a-collection-using-the-html-begincollectionitem-helper/40541892#40541892) for some options –  Jan 21 '18 at 00:32
  • @StephenMuecke Yeah sorry this is one of those where I didn't entirely know how to ask the question properly. While I'm dealing with adding items to a collection, my question isn't actually related to that. Say I have a partial with just a text box. User enters string into box, hits F5 to refresh, and then box is auto populated with value. I didn't have to write any code to make it repopulate... it's just built in behavior. Can I take advantage of that behavior when reloading an ajax partial or must I write code to post and repopulate the box myself? – BVernon Jan 21 '18 at 07:41
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/163569/discussion-between-stephen-muecke-and-bvernon). –  Jan 21 '18 at 07:42

0 Answers0