views:

63

answers:

2

I'd like to have a section of my page where, lets say, some basic contact fields can be entered. Without having to hit the "Save" submit button, the user can add more contacts by hitting a "+" button, which adds more fields to the page.

This would be fairly easy in standard web forms, but I'm a little lost as to how it should work in MVC.

How should I do it, do you think?

Thanks,

Matt.

A: 

If you are asking how it should go in MVC perspective then:

  1. Your contact form is a View and in the action attribute of the form residing in that view, you write the path to the Controller which will handle the data sent by this form.

  2. Now you create a controller to handle the data sent by the above form and also make calls to the Model which will interact with the database (for example adding/updating form data into the database)

  3. You create a Model which will actually do the database queries to insert/update the form data into the databse.

Hence, all parts of MVC are covered and in correct MVC perspective.

Thanks

Sarfraz
+3  A: 

I saw a blog post recently by Steve Sanderson that showed one way to do this in ASP.NET MVC 2. If you look at the blog post, it also links to an example in ASP.NET MVC 1.0.

http://blog.stevensanderson.com/2010/01/28/editing-a-variable-length-list-aspnet-mvc-2-style/

Dave Cluderay