Hi, when converting my app to your equivalent included example code- everything works except for add./insert which results in an 'object reference not set to an instance of an object'
The 'param' has a value of null.
Your code example works for add/insert- but I have to put in the value of the key column to make it work.
My App uses a sql table where the key id column is autogenerated in SQL Server itself as an identity column.
The contoller code is as follows:
public ActionResult Normal_Insert([FromBody] CRUDModel<Prdsrv> param)
{
string connectionString = @"Server=WIN10DESKTOP\VS2019;Database=WorkManagerV4;Trusted_Connection=True;";
SqlConnection con = new SqlConnection(connectionString);
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "SET IDENTITY_INSERT PRDSRV ON";
cmd.ExecuteNonQuery();
cmd.CommandText = "INSERT INTO PRDSRV(PRODSERVID,PRODSERVDESC,LASTUPDATED,SERVICESHORTDESC,SERVICEDESC) VALUES(@PRODSERVID,@PRODSERVDESC,@LASTUPDATED,@SERVICESHORTDESC,@SERVICEDESC)";
cmd.Parameters.AddWithValue("@PRODSERVID", param.Value.Prodservid);
cmd.Parameters.AddWithValue("@PRODSERVDESC", param.Value.Prodservdesc);
cmd.Parameters.AddWithValue("@LASTUPDATED", DateTime.Now);
cmd.Parameters.AddWithValue("@SERVICESHORTDESC", param.Value.Serviceshortdesc);
cmd.Parameters.AddWithValue("@SERVICEDESC", param.Value.Servicedesc);
cmd.ExecuteNonQuery();
con.Close();
return Json(param.Value);
}
the index cshtml is as follows
<ejs-grid id="Grid" allowPaging="true" allowSorting="true" allowFiltering="true" toolbar="@(new List<string>() { "Add", "Edit", "Delete","Update","Cancel" })">
<e-data-manager url="/Prdsrvs/UrlDataSource" adaptor="UrlAdaptor" ></e-data-manager>
<e-data-manager url="@Url.Action("UrlDatasource", "Prdsrvs")" adaptor="UrlAdaptor" InsertUrl="/Prdsrvs/Normal_Insert" updateUrl="/Prdsrvs/Normal_Update" removeUrl="/Prdsrvs/Normal_Delete"></e-data-manager>
<e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Dialog"> </e-grid-editSettings>
<e-grid-pagesettings pageSize="10"></e-grid-pagesettings>
<e-grid-columns>
<e-grid-column field="Prodservid" headerText="Product Service ID" textAlign="Right" width="100" isPrimaryKey="true" isIdentity="true"></e-grid-column>
<e-grid-column field="Prodservdesc" headerText="Product Service Description" width="300"></e-grid-column>
<e-grid-column field="Lastupdated" headerText="Last Updated" width="300"></e-grid-column>
<e-grid-column field="Serviceshortdesc" headerText="Short Description" width="300"></e-grid-column>
<e-grid-column field="Servicedesc" headerText="Service Description" width="300"></e-grid-column>
</e-grid-columns>
</ejs-grid>
Obviously, i would rather have the sql table take care of the incrementing the key value
What mistake am I making? thanks