Handling Multiple Entries and One Time Post in ASP.NET MVC

Introduction

One type of Data Entry patterns in Web Application is multiple data entry. Examples of these multiple data entry are orders entry, guests registration, etc. In this example we will be using Client Registration. Below is a screenshot on what we will be working.



Download:


What does it do?
  1. Allow users to enter unlimited clients by clicking the New Client button and enters the information of the client.
  2. The User can delete the entry without server round trips (it's happening on the client side).
  3. Save all the entries at once.
Technologies used

  • ASP.NET MVC 4
  • jQuery
  • CSS
  • HTML 5

How do we do this?

One approach is to loop through the web form and capture the values in the form. We can do this in the controller. That's it!

The Code:

Let's create the client model first.



The View:

We are going to use plain HMTL and jQuery to do the data capturing. We use jQuery to manipulate the DOM.



The Controller:

In the controller, we loop through the form and capture the data. Save it to a list and we can save it to SQL Server data store or process further.



How to Verify:

One way to verify that the data has been captured is by placing a breakpoint and run the application in a debug mode.













Hope this article helps. Share it with your friends!


3 comments

This article is awesome, thanks very much, just what i needed but what if my fields contain drop downs which user are going to select, the items in the drop downs are retrieve from the database. How am I going to go about that, any help will be highly appreciated and once again thanks so much for this nice piece of article.

Reply

This post has been extremely interesting and educative.
Thanks for posting

Reply

So neatly don.
But, two questions:
1). how do you apply validations against all the dynamically created form fields?
2) Could you update the example adding 2 or 3 dropdown list box controls with different options?

Regards....

Reply