1

I am using MVC 5 and Entity framework 6 (Database First) in my application. I need to update "value" field in View page\index.cshtml. Is it possible to use @Html.EditorFor to edit Value field for each Item on single button click? Here is the code in index.cshtml

<table>
 <tr>
        <th>
            Number
        </th>
        <th>
            Name
        </th>
        <th>
            Value
        </th>
        <th>
            Description
        </th>     
    </tr>
     foreach (var item in Model) {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.number)                
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.name)
            </td>
            <td>
                @Html.EditorFor(modelItem => item.value)
             @*@Html.ValidationMessageFor(modelItem => item.value) *@       
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.description)
            </td>
  @* <td>
       @Html.ActionLink("Edit", "Edit", new { id=item.id })      
    </td>*@
</tr>
</table>
<div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <input type="submit" value="Save" class="btn btn-default" />          
        </div>
</div>

On clicking Save button I should update the data in Value field for any number of rows. It's done in Database First so action for Edit,View,Details are included in Controller.

1 Answers1

0

You'll have to put everything in a to post the details to the server, then you can manage the posted elements. You'll post a list of itens. Maybe this will help you: How can I post a list of items in MVC

Community
  • 1
  • 1
Sornii
  • 421
  • 3
  • 11