I am new to asp.net mvc. In my project i have to add a table where user can enter details and select options from drop down . And when the user clicks add button a row must be added to the table with all fields(that includes textbox, dropdown list). Also when the user clicks on delete button that particular row must be removed from the table. By default when the page loads I should have two rows in the table with all required fields. I need solution for the following questions
- How to achieve the above said task.
- I also need to save the table details. So how to pass the table details to the controller ?
- After saving the details when the user clicks on edit button I should load all the details in the table. Please help me in this
I also searched a lot but none of the example includes dropdown option in dynamic table. Please help me in this task. Thanks in advance for all the volunteers.
I suggest using the BeginCollectionItem() helper that Steve Sanderson created
http://blog.stevensanderson.com/2010/01/28/editing-a-variable-length-list-aspnet-mvc-2-style/
it achieves exactly what you want, and he goes over it step by step with a working example. I've used it in several of my projects.
I would have left some links in a comment, but I don't have enough rep yet. So I'll put this here as an answer and expound on it more than I would in a comment. But this is just general info. Please provide more details for more specific answers.
First of all, what version of MVC are you working with? What does your data model look like? Are you using an EntityModel? Have you considered a client side MVC or MVVM framework or library, such as AngularJS or Knockout?
Contingent on your answers to those questions, an answer to your question might be...
It might seem like a good bit of overhead, but 1 & 2 can save you a lot of time if you're going to maximize use of Razor views.
You may want to only exchange application level data with the client most of the time though. You could build a client side architecture using a framework like AngularJS, or build your own framework around a library like Knockout, to bind to your data, and allow the markup (such as a custom directive's template in AngularJS, for example) to actually be generated and rendered via a client side controller.
For an opensource, standardized look and feel, I would recommend looking into Boostrap for a set relatively easy to use of components and layout/styling conventions. You can use it barebones or incorporate it with other js libs, like this.