Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a table like below. it have 10 rows. i want to save the data entered in this table to database. how can it possible in mvc4

please help me

kunjammu

<table id="list" cellspacing="0" cellpadding="0">
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.Date)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.CategoryID)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.TimeTaken)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Comments)
            </th>
            <th>
            </th>
        </tr>
        @for (int i = 0; i < 10; i++)
        {
             <tr>
            <td>
                @Html.TextBoxFor(model => model.Date, new { @id = "date" + i, @class = "datepicker" })
            </td>
            <td>
                @Html.DropDownListFor(model => model.CategoryID, (IEnumerable<SelectListItem>)ViewData["categories"], new { @id = "category" + i })
            </td>
            <td>
                @Html.TextBoxFor(model => model.TimeTaken, new { @id = "time" + i, @class = "time" })
            </td>
            <td>
                @Html.TextBoxFor(model => model.Comments, new { @id = "comments" + i })
            </td>
        </tr>
        }
    </table>
Posted
Updated 7-Apr-14 22:25pm
v2

1 solution

This is simple, like you need to have FormCollection as argument in you function. This way you can get the values. For more knowledge just go to this link:

Get dynamically generated multiple row control values in MVC4
 
Share this answer
 
Comments
Kunjammu 8-Apr-14 7:27am    
what i mean is from dynamically generated table i want to save data
Er. Puneet Goel 8-Apr-14 7:31am    
yes yes here in this page, it show how you can get value and save the data (in database)
Kunjammu 8-Apr-14 7:46am    
since i am a beginner in mvc, can you please give a simple example....
Er. Puneet Goel 8-Apr-14 7:51am    
Actually this is what is reuired in MVC. I can understand that for one who begin with mvc it very difficult to get value of multiple control on Controls. So i suggest you to please undergo below article (or google in case you don't find them sufficient about MVC) to get a base to work on MVC:

http://www.codeproject.com/Articles/741632/Start-With-MVC-Push-Start-For-Beginners-Part
http://www.codeproject.com/Articles/747868/Start-With-MVC-Push-Start-For-Beginners-Part
http://www.codeproject.com/Articles/750747/MVC-With-Ajax-Push-Start-For-Beginners-Part

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900