views:

27

answers:

1

I have an application that I am writing in ASP.NET MVC 2 following the Nerd Dinner tutorial. I am very much a beginner and was looking for examples/tutorials I could follow that would enable me to learn how to code the following scenario:

  • A user has the option to select an option from a dropdown.
  • If the option is not there then they can enter a new option and add it to the database and list in the dropdown.
  • I would like this to be done without the user leaving the page and what they have entered so far.
  • I am using a simple Entity Framework 4.0 model which I have built a repository on top of so I have methods I can call to save the filled in user information.
  • If the entry already exists in the database then I would like to offer the user the chance to either select that entry or to continue adding the entry they request because it can be a list of names and of course you can have more than one person with the same name.
+1  A: 

I have implemeted this and it follows the following workflow:

1) Provide a button next to the select list to add items

2) Populate the drop-downlist when the page loads

3) When the add button is clicked, implement the UI as you like, we use a jquery dialog box.

4) Post the value to a view (via jQuery Ajax) The view should return a JsonResult

5) Check to see if the item exists, get existing id if exists or add and get new id

6) Returns a JsonResult that contains the new list and the id

7) In the reply to the ajax post, repopulate the select list using jquery and select the item.

HTH

Mark Redman
That's great. Would like to see a code example if possible? If you don't want to post it on here could you email?
Ian Roke
The code for the various parts are fairly embedded in our framework, ie re-usable dialogs, Methods that generate standard Json Error/Success results, jquery validation/post custom plugins and functions...it would be hard to collect these together...Its a pretty good excerise to get you going on all this stuff and will be happy to give you pointers along the way, feel free to email, see my profile for address.
Mark Redman
Here was one of my questions on this, some info on the JsonResult: http://stackoverflow.com/questions/2544315/asp-net-mvc-what-is-the-correct-way-to-return-html-from-controller-to-refresh-se
Mark Redman
Sorry I am just a visual learner type of guy! Thanks for your pointers I will grab the bits I need from the net and get in touch via email if I need to. Thanks for your help.
Ian Roke