Use jqGrid to display database tables. If the database table has a date type, you must declare the field type that can be empty in poco. See the following FillinDate field:
Public class Project2Weekly
{
Public int Id {get; set ;}
Public string Progress {get; set ;}
Public string Problem {get; set ;}
Public string NextPlan {get; set ;}
Public string Evidence {get; set ;}
Public {get; set ;}
Public string FillinMan {get; set ;}
Public int Pid {get; set ;}
}
After editing and saving table data, you must call the JqGrid. EditParams method to convert the data on the Form, for example:
Public JsonResult EditWeekly ()
{
NameValueCollection nvc = Request. Form;
Project2Weekly model = <Project2Weekly> (nvc );
Manager. EditWeekly (model );
Return Json (new {success = true });
}
In practice, we found that the date type on Form is always not saved in the database. Tracking found that DateTime in poco? The data type is in JqGrid. the EditParams method is not recognized as the DateTime type, but is recognized as "Nullable '1" (System. nullable '1 [System. dateTime]), causing the value to be set to null. The source code of the JqGrid. EditParams method is as follows:
Public static T EditParams <T> (NameValueCollection nvc)
{
Type type = typeof (T );
PropertyInfo [] pis = type. GetProperties ();
T t = (T) Activator. CreateInstance (type );
Foreach (PropertyInfo pi in pis)
{
String data = nvc [pi. Name] = null? "": Nvc [pi. Name]. ToString (). Trim ();
Dynamic value;
Switch (pi. PropertyType. Name)
{
If (data = "")
Value = DateTime. MinValue;
Else
{
Value = Convert. ToDateTime (data );
If (value = DateTime. MinValue)
Value = DateTime. Now;
}
Break;
.
.
.
Case "String ":
Value = data;
Break;
Break;
}
Pi. SetValue (t, value, null );
}
Return t;
}
}
The solution to this problem is also very simple. Add a line in the case "DateTime" code to process the "Nullable '1" type. The code is modified as follows:
Switch (pi. PropertyType. Name)
{
Case "DateTime ":
If (data = "")
Value = DateTime. MinValue;
Else
{
Value = Convert. ToDateTime (data );
If (value = DateTime. MinValue)
Value = DateTime. Now;
}
Break;