title: how to dynamically edit the bind data in sql using mvc3 web grid
body: <p>i am new to mvc.. i have a task that, i have to bind data from  existing table in sql using asp.net mvc3(Razor) Web Grid .. now i have to edit the data in webGrid.. i dont know how the edit operation is going to made... Plzz Help me out...</p>
  
  <p>i have given my bind data.. plz let me know how to edit it...</p>
  
  <p>Controller:</p>
  
  <pre><code>    public ActionResult Index()
      {
          var list = GetList();
          return View(list); 
      }
  
      public List&lt;Teacher&gt; GetList()
      {
          var modelList = new List&lt;Teacher&gt;();
          using (SqlConnection conn = new SqlConnection(@"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Demo;Data Source=CIPL41\SQLEXPRESS"))
          {
              conn.Open();
              SqlCommand dCmd = new SqlCommand("Select T_Id,T_Name,T_Address,Sub_Id from teacher", conn);
              SqlDataAdapter da = new SqlDataAdapter(dCmd);
              DataSet ds = new DataSet();
              da.Fill(ds);
              conn.Close();
              for (int i = 0; i &lt;= ds.Tables[0].Rows.Count - 1; i++)
              {
                  var model = new Teacher();
                  model.T_Id = Convert.ToInt32(ds.Tables[0].Rows[i]["T_Id"]);
                  model.T_Name = ds.Tables[0].Rows[i]["T_Name"].ToString();
                  model.T_Address = ds.Tables[0].Rows[i]["T_Address"].ToString();
                  model.Sub_Id = ds.Tables[0].Rows[i]["Sub_Id"].ToString();
                  modelList.Add(model);
              }
          }
          return modelList;
      }
      //
  </code></pre>
  
  <p>Index.cshtml</p>
  
  <pre><code>    @model IEnumerable&lt;MvcApplication1.Models.Teacher&gt;
  
      @{
        ViewBag.Title = "Index";
        }
  
      &lt;h2&gt;Index&lt;/h2&gt;
      @using (Html.BeginForm("Index", "Teacher"))
         {
  
       &lt;table&gt;
  &lt;tr&gt;
      &lt;th&gt;&lt;/th&gt;
      &lt;th&gt;
          T_Id
      &lt;/th&gt;
      &lt;th&gt;
          T_Name
      &lt;/th&gt;
      &lt;th&gt;
          T_Address
      &lt;/th&gt;
      &lt;th&gt;
          Sub_Id
      &lt;/th&gt;
  
  &lt;/tr&gt;
  
   @foreach (var item in Model)
   {
  
  &lt;tr&gt;
      &lt;td&gt;
          @Html.ActionLink("Edit", "Edit", new { id=item.T_Id }) |
         @* @Html.ActionLink("Details", "Details", new { id=item.T_Id }) |*@
          @Html.ActionLink("Delete", "Delete", new {  id=item.T_Id })
      &lt;/td&gt;
      &lt;td&gt;
         @Html.TextBox("T_Id",  item.T_Id , new { @style = "width:100px;" })
      &lt;/td&gt;
      &lt;td&gt;
          @Html.TextBox("T_Name",  item.T_Name , new { @style = "width:100px;" }) 
          &lt;/td&gt;
      &lt;td&gt;
          @Html.TextBox("T_Address",  item.T_Address , new { @style = "width:100px;" }) 
      &lt;/td&gt;
      &lt;td&gt;
          @Html.TextBox("Sub_Id",item.Sub_Id,new { @style = "width:100px;"})
      &lt;/td&gt;
  
  &lt;/tr&gt;
    }
  
  
    &lt;/table&gt;
  </code></pre>
  
  <p>Plz help me out....</p>