Id column from database model shows as null
Id column from database model shows as null
I am learning how to use Editor in a .NET MVC project and am unable to solve an issue.
My database table has a primary key field called "Id".
While editor shows all of the other fields in my table with their correct values, the Id is consistently null.
What do I need to change so that Id is not null?
On a related note, changes I make on the inline editor do not persist on the database. My theory was that the null Id was part of it -- however as I receive no compiler, runtime, nor browser errors, I am not sure how to proceed.
Thank you
Controller Action
public ActionResult Table()
{
var settings = Properties.Settings.Default;
var formData = HttpContext.Request.Form;
using (var db = new Database(settings.DbType, settings.DbConnection))
{
DtResponse response;
try
{
response = new Editor(db, "TestTable")
.Model<TestTable>()
.Field(new Field("Id"))
.Field(new Field("Campus"))
.Field(new Field("Teacher"))
.Field(new Field("CourseSectionId"))
.Process(formData)
.Data();
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
return Json(response, JsonRequestBehavior.AllowGet);
}
}
Model
public class TestTable
{
public int Id { get; set; }
public string Campus { get; set; }
public string Teacher { get; set; }
public string CourseSectionId { get; set; }
}
This question has an accepted answers - jump to answer
Answers
Change:
to be:
and remove:
and
You don't need to include the primary key column as a field - just having it as the primary key is enough.
See also the documentation about primary keys here.
Allan