简体   繁体   中英

Best way to implement an ASP.NET MVC list (C#)

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?

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/

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM