How to edit data in GridView using asp.net MVC?
===

i am already bind the data in gridview using sqlswever ..am using storeprocedure ..
  i want help me Gridview edit the data 
   model code....
 --------------------

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Data;
    using System.Data.SqlClient;
    using System.Data.Entity;
    
    namespace Gridview_BugTracker.Models
    {
        public class BugTracker_DataHelper
          {
     
            public static List<BugTracker_DataHelper> GetList{get;set;}
    
              public string ProjectId { get; set; }
              public string projectName { get; set; }           
              public string Description { get; set; }
               public  string status { get; set; }         
            }     
            
       }
      controller code
     ------------------
     using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using System.Data;
    using Gridview_BugTracker.Models;
    using System.Data.SqlClient;
    using System.Data.Entity;
    
    namespace Gridview_BugTracker.Controllers
    {
        public class ProjectsController : Controller
        {
            //
            // GET: /Projects/
    
    
            public ActionResult Index()
            {
                var bugedlist = GetList(); 
                return View(bugedlist);
            }
            [HttpGet]
            public ActionResult Edit(int projectId)
            {
                 BugTracker_DataHelper bugedit = new BugTracker_DataHelper();           
                 var edit = EditList();
                 bugedit.ProjectId =Convert.ToString(projectId);
                 return View(edit);      
            }
    
            public List<BugTracker_DataHelper> GetList()
            {
                var modelList = new List<BugTracker_DataHelper>();
                using (SqlConnection conn = new SqlConnection(@"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=BugTracker;Data Source=SSDEV6\SQLEXPRESS"))
                {
                    conn.Open();
                    SqlCommand dCmd = new SqlCommand("Select * from Projects", conn);
                    SqlDataAdapter da = new SqlDataAdapter(dCmd);
                    DataSet ds = new DataSet();
                    da.Fill(ds);
                    conn.Close();
                    for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
                    {
                        var model = new BugTracker_DataHelper();
                        model.ProjectId = ds.Tables[0].Rows[i]["ProjectId"].ToString();
                        model.projectName = ds.Tables[0].Rows[i]["projectName"].ToString();
                        model.Description = ds.Tables[0].Rows[i]["Description"].ToString();
                        model.status = ds.Tables[0].Rows[i]["Status"].ToString();
                        modelList.Add(model);
                    }
                }
                return modelList;
            }
    
         [HttpPost]   
        public ActionResult EditList()
            {
                var editlist = new List<BugTracker_DataHelper>();
                using (SqlConnection editconn=new SqlConnection(@"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=BugTracker;Data Source=SSDEV6\SQLEXPRESS"))
                {
                    editconn.Open();
                    var modeledit = new BugTracker_DataHelper();
                    SqlCommand ecmd = new SqlCommand("EditGetList", editconn);
                    ecmd.CommandType = CommandType.StoredProcedure;
                    ecmd.Parameters.Add("@projectID", SqlDbType.Int).Value = modeledit.ProjectId;
                    Object prjid = ecmd.ExecuteNonQuery();
                    editconn.Close();                 
    
                    editlist.Add(modeledit);
                }
                return View(editlist);
            }
     

   view page  in GridView Bind the Data
-------------------------------------------

     <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<IEnumerable<Gridview_BugTracker.Models.BugTracker_DataHelper>>" %>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Index</title>
    </head>
    <body>
        <div>
        <h2>Index</h2>
    <table>
        <tr>         
            <th>
                ProjectName
            </th>
            
            <th>
               Status
            </th>       
        
        </tr>
    
     <% foreach (var item in Model) { %> 
     
        <tr> 
             
            <td> 
                <%:Html.LabelForModel(item.projectName) %> 
            </td> 
           
            <td>
             <%:Html.LabelForModel(item.status) %>
            </td>
    
             <td>
                <%: Html.ActionLink("Edit", "Edit", new { projectId = item.projectName})%> |
                <%: Html.ActionLink("Details", "Details", new { projectId = item.Description })%> |
                <%: Html.ActionLink("Delete", "Delete", new { projectId = item.status })%>
            </td>
            
            </tr>
    
           <%} %>
    
    </table>
        </div>
    </body>
    </html>

------------------------------------
view page code for Edit 
--- --------------------------

    <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/SiteMaster.Master" Inherits="System.Web.Mvc.ViewPage<Gridview_BugTracker.Models.BugTracker_DataHelper>" %>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
        editindex
    </asp:Content>
    
    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    
    <h2>editindex</h2>
    
    
        <fieldset>
            <legend>EDit</legend>        
           
            <div class="editor-label">
               <%:  Html.LabelFor(Model => Model.ProjectId) %>
            </div>
            <div class="editor-field">
               <%: Html.EditorFor(model => model) %>
               <%:  Html.ValidationMessageFor(model => model.projectName) %>
            </div>
    
            <div class="editor-label">
               <%: Html.LabelFor(model => model.Description) %>
            </div>
            <div class="editor-field">
                <%: Html.EditorFor(model => model.Description) %>
                <%: Html.ValidationMessageFor(model => model.Description)%>
            </div>
    
    
             <div class="editor-label">
               <%:  Html.LabelFor(model => model.status) %>
            </div>
            <div class="editor-field">
              <%:   Html.EditorFor(model => model.status) %>
              <%:    Html.ValidationMessageFor(model => model.status) %>
            </div>   
            
    
            <p>
                <input type="submit" value="Save" />
            </p>
        </fieldset>
    </asp:Content>

-----------------------
when am click the EDIT button getting ERROR
-----------------------------------------------

Server Error in '/' Application.
--------------------------------------------------------------------------------

The parameters dictionary contains a null entry for parameter 'projectId' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Edit(Int32)' in 'Gridview_BugTracker.Controllers.ProjectsController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 


