This question is locked. New answers and comments are not allowed.
For my grid I'm using
The grid binds and loads data fine - works really well. My issue that I'm getting the "The requested URL returned 500 - error" on Insert, Update and Delete only. The methods execute and the database is updated, but the return triggers the error and leaves the popup open. Since my ViewModel is not part of my Entity, for each method I pass the data from the ViewModel to the Entity Model and process the commands (Insert, Update, Delete.) On each method I'm returning a new GridModel but I haven't been able to resolve the issue. I really have no idea what I'm doing wrong! Please help!
Here's my grid:
Here's my ViewModel:
And here's my controller:
Thanks!
JT
- the latest MVC build - 2011.2.715
- Entity Framework - v4.0.30319
- Ajax binding with a seperate ViewModel
-
GridEditMode
.PopUp
The grid binds and loads data fine - works really well. My issue that I'm getting the "The requested URL returned 500 - error" on Insert, Update and Delete only. The methods execute and the database is updated, but the return triggers the error and leaves the popup open. Since my ViewModel is not part of my Entity, for each method I pass the data from the ViewModel to the Entity Model and process the commands (Insert, Update, Delete.) On each method I'm returning a new GridModel but I haven't been able to resolve the issue. I really have no idea what I'm doing wrong! Please help!
Here's my grid:
@(Html.Telerik().Grid<MetaDataMVC.Models.CalendarViewModel>() .Name("Grid") .ToolBar(tools => { tools.Insert().ButtonType(GridButtonType.ImageAndText); }) .DataKeys(keys => keys.Add(m => m.ID)) .DataBinding(dataBinding => { dataBinding.Ajax() .Select("_RptCalendar", "Report") .Update("_UpdateCalendar", "Report") .Insert("_InsertCalendar", "Report") .Delete("_DeleteCalendar", "Report"); } ) .Columns(columns => { columns.Bound(r => r.OBJ_ID).Title("Object ID").Width(70); columns.Bound(r => r.RPT_NO).Title("Rpt No.").Width(70); columns.Bound(r => r.RPT_NAME).Title("Report Name"); columns.Bound(r => r.ASSIGNED_TO).Title("Assigned To"); columns.Bound(r => r.STATUS).Title("Status"); columns.Bound(r => r.START_DATE).Title("Start Date"); columns.Bound(r => r.DUE_DATE).Title("Due Date"); columns.Bound(r => r.COMPLETED_DATE).Title("Completed"); columns.Command(commands => { commands.Edit().ButtonType(GridButtonType.Image); commands.Delete().ButtonType(GridButtonType.Image); }).Width(80); } ) .Editable(editing => editing.Mode(GridEditMode.PopUp)) .Pageable(paging => paging.PageSize(20)) .Sortable() .Groupable() .Selectable() .Filterable() .Reorderable(reorder => reorder.Columns(true)) .PrefixUrlParameters(false) )Here's my ViewModel:
public class CalendarViewModel { public int ID { get; set; } public int OBJ_ID { get; set; } [Required(ErrorMessage = " Please select delegate.")] public int ASSIGNED_TO_ID { get; set; } public int LU_OP_STATUS_ID { get; set; } [Required(ErrorMessage = " Start Date is Required.")] [DataType(DataType.Date)] public System.DateTime START_DATE { get; set; } [Required(ErrorMessage = " Due Date is Required.")] [DataType(DataType.Date)] public System.DateTime DUE_DATE { get; set; } [DataType(DataType.Date)] public Nullable<System.DateTime> COMPLETED_DATE { get; set; } public string DELAY_REASON { get; set; } public string AUDIT_CREATED_BY { get; set; } public System.DateTime AUDIT_CREATED_DATE { get; set; } public string AUDIT_UPDATED_BY { get; set; } public System.DateTime AUDIT_UPDATED_DATE { get; set; } public string ASSIGNED_TO { get; set; } public int RPT_NO { get; set; } public string RPT_NAME { get; set; } public string STATUS { get; set; } }And here's my controller:
//Calendar Select [GridAction] public ActionResult _RptCalendar(int id) { return ReportCalendarData(id); } //Calendar Insert [HttpPost] public ActionResult _InsertCalendar(CalendarViewModel cal, int id) { if (ModelState.IsValid) { if (cal.START_DATE == cal.DUE_DATE) { cal.DUE_DATE = cal.DUE_DATE.AddDays(1); } MD2_RPT_CALENDAR newCal = new MD2_RPT_CALENDAR(); newCal.OBJ_ID = id; newCal.ASSIGNED_TO_ID = cal.ASSIGNED_TO_ID; newCal.LU_OP_STATUS_ID = cal.LU_OP_STATUS_ID; newCal.START_DATE = cal.START_DATE; newCal.DUE_DATE = cal.DUE_DATE; newCal.COMPLETED_DATE = cal.COMPLETED_DATE; newCal.DELAY_REASON = cal.DELAY_REASON; newCal.AUDIT_CREATED_BY = User.Identity.Name; newCal.AUDIT_CREATED_DATE = DateTime.Now; newCal.AUDIT_UPDATED_BY = User.Identity.Name; newCal.AUDIT_UPDATED_DATE = DateTime.Now; db.Entry(newCal).State = EntityState.Added; db.SaveChanges(); } return ReportCalendarData(id); } //Calendar Update [HttpPost] public ActionResult _UpdateCalendar(CalendarViewModel cal, int id) { var md_objID = cal.OBJ_ID; if (cal.START_DATE == cal.DUE_DATE) { cal.DUE_DATE = cal.DUE_DATE.AddDays(1); } if (ModelState.IsValid) { MD2_RPT_CALENDAR newCal = new MD2_RPT_CALENDAR(); newCal.OBJ_ID = cal.OBJ_ID; newCal.MD_RPT_CALENDAR_ID = cal.ID; newCal.ASSIGNED_TO_ID = cal.ASSIGNED_TO_ID; newCal.LU_OP_STATUS_ID = cal.LU_OP_STATUS_ID; newCal.START_DATE = cal.START_DATE; newCal.DUE_DATE = cal.DUE_DATE; newCal.COMPLETED_DATE = cal.COMPLETED_DATE; newCal.DELAY_REASON = cal.DELAY_REASON; newCal.AUDIT_CREATED_BY = cal.AUDIT_CREATED_BY; newCal.AUDIT_CREATED_DATE = cal.AUDIT_CREATED_DATE; newCal.AUDIT_UPDATED_BY = User.Identity.Name; newCal.AUDIT_UPDATED_DATE = DateTime.Now; db.Entry(newCal).State = EntityState.Modified; db.SaveChanges(); } return ReportCalendarData(md_objID); } //Calendar Delete [HttpPost, ActionName("_DeleteCalendar")] public ActionResult DeleteConfirmed(int id) { MD2_RPT_CALENDAR md_cal = db.MD2_RPT_CALENDAR.Find(id); db.MD2_RPT_CALENDAR.Remove(md_cal); db.SaveChanges(); return RedirectToAction("Details"); } //Calendar Data private ActionResult ReportCalendarData(int id) { var model = from d in db.MD2_RPT_CALENDAR where d.MD2_OBJ.MD_OBJ_ID == id orderby d.START_DATE select new CalendarViewModel { ASSIGNED_TO_ID = d.ASSIGNED_TO_ID, AUDIT_CREATED_BY = d.AUDIT_CREATED_BY, AUDIT_CREATED_DATE = d.AUDIT_CREATED_DATE, AUDIT_UPDATED_BY = d.AUDIT_UPDATED_BY, AUDIT_UPDATED_DATE = d.AUDIT_UPDATED_DATE, COMPLETED_DATE = d.COMPLETED_DATE, DUE_DATE = d.DUE_DATE, DELAY_REASON = d.DELAY_REASON, LU_OP_STATUS_ID = d.LU_OP_STATUS_ID, ID = d.MD_RPT_CALENDAR_ID, OBJ_ID = d.OBJ_ID, START_DATE = d.START_DATE, ASSIGNED_TO = d.MD2_CONTACT.LAST_NAME + ", " + d.MD2_CONTACT.FIRST_NAME, RPT_NAME = d.MD2_OBJ.PHYS_NAME, RPT_NO = d.MD2_OBJ.MD2_RPT.RPT_NO, STATUS = d.MD2_LOOKUP.LOOKUP_DESC }; return View(new GridModel { Data = model }); } Thanks!
JT