Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I change item.col1, item.col2 and item.col3 to reflect the updated or changed value in the TextBoxes for the row the submit button is pressed?

Index.cshtml
HTML
@model IEnumerable<Editing.Models.Table1>

@using (Html.BeginForm("Index", "Home", new { Idt = item.Idt, col01 = item.col1, col02 = item.col2, col03 = item.col3       {
        <tr>
            <td>
                @Html.TextBoxFor(modelItem => item.Idt)
            </td>
            <td>
                @Html.TextBoxFor(modelItem => item.datetime0)
            </td>
            <td>
                @Html.TextBoxFor(modelItem => item.col1)
            </td>
            <td>
                @Html.TextBoxFor(modelItem => item.col2)
            </td>
            <td>
                @Html.TextBoxFor(modelItem => item.col3)
            </td>
            <td>

                    <input type="submit" id="Edit" value="Edit" />

            </td>
        </tr>
    }

HomeController.cs
C#
public class HomeController : Controller
{
    private testContext db = new testContext();
    [HttpPost]
    public ActionResult Index(int Idt, string col01, string col02, string col03)
    {
            var dataToUpdate=db.Data1.SingleorDefault(o=> o.Idt ==Idt);
            dataToUpdate.datetime0=DateTime.Now.ToString();
            dataToUpdate.col1=col01;
            dataToUpdate.col2=col02;
            dataToUpdate.col3=col03;
            db.Entry(dataToUpdate).State=EntityState.Modified;
            db.SaveChanges();
            return View(db.Data1.ToList());
     }
}
Posted
Updated 10-Feb-15 6:35am
v2

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