Hi all,
I use a ViewModel when binding to a grid.
However when using the filtering function I get the following:
Invalid property or field - 'UserName' for type: ErrorLog
Username is only a property in the ErrorLogViewModel
The code to fill my view model is:
public ActionResult ListErrors([DataSourceRequest]DataSourceRequest request)
{
IQueryable<ErrorLog> errorLogs = (IQueryable<ErrorLog>)db.ErrorLogs.Include(e => e.User).OrderByDescending(e => e.ErrorLogId);
DataSourceResult result = errorLogs.ToDataSourceResult(request, errorLog => new ErrorLogViewModel
{
ErrorLogId = errorLog.ErrorLogId,
Message = errorLog.AdditionalMessage,
Timestamp = errorLog.Timestamp,
UserName = errorLog.User.UserName
});
return Json(result);
}
Thanks,
Keith.
I use a ViewModel when binding to a grid.
However when using the filtering function I get the following:
Invalid property or field - 'UserName' for type: ErrorLog
Username is only a property in the ErrorLogViewModel
The code to fill my view model is:
public ActionResult ListErrors([DataSourceRequest]DataSourceRequest request)
{
IQueryable<ErrorLog> errorLogs = (IQueryable<ErrorLog>)db.ErrorLogs.Include(e => e.User).OrderByDescending(e => e.ErrorLogId);
DataSourceResult result = errorLogs.ToDataSourceResult(request, errorLog => new ErrorLogViewModel
{
ErrorLogId = errorLog.ErrorLogId,
Message = errorLog.AdditionalMessage,
Timestamp = errorLog.Timestamp,
UserName = errorLog.User.UserName
});
return Json(result);
}
Thanks,
Keith.