This question is locked. New answers and comments are not allowed.
I am writing a project that uses CSLA with CodeSmith generated entities, and I have been having a problem getting a basic grid up and running. Eventually, I want to support Batch Editing, but given these issues, I've simplified my code for the time being.
Basically, when I run the application, everything renders correctly, and I can get to the point where I need to actually insert the item into the list, but nothing happens except that the new grid row is wiped back to default values.
When I use the debugger to see what is going on, and both the Insert/Edit and Cancel buttons are invoking the Index() method (the start up method for the view). I'm baffled as to why this is happening as my databinding section is exactly the same as many examples that I have seen. It could easily be something else, but can anybody confirm/deny that CSLA could cause something like this? Any help would be greatly appreciated!
View
Controller
Basically, when I run the application, everything renders correctly, and I can get to the point where I need to actually insert the item into the list, but nothing happens except that the new grid row is wiped back to default values.
When I use the debugger to see what is going on, and both the Insert/Edit and Cancel buttons are invoking the Index() method (the start up method for the view). I'm baffled as to why this is happening as my databinding section is exactly the same as many examples that I have seen. It could easily be something else, but can anybody confirm/deny that CSLA could cause something like this? Any help would be greatly appreciated!
View
@using Telerik.Web.Mvc.UI@model Test.App.MVC.Models.ShipmentModel@{ Layout = "~/Views/Shared/_StandardLayout.cshtml";} @(Html.Telerik().Grid(Model.Shipment.ItemList).Name("TestGrid") .DataKeys(keys => { keys.Add(p => p.ItemID); }) .ToolBar(commands => { commands.Insert().ButtonType(GridButtonType.ImageAndText).ImageHtmlAttributes(new { style = "margin-left:0" }); }) .DataBinding(dataBinding => { dataBinding.Ajax() .Select("SelectDefaultReferences", "Home") .Insert("InsertDefaultReferences", "Home") .Update("SaveDefaultReferences", "Home"); }) .Resizable(resizing => resizing.Columns(true)) .Reorderable(reorderable => reorderable.Columns(true)) .Columns(columns => { columns.Bound(p => p.FreightClass).Width(30); columns.Bound(p => p.Dimension.UnitOfMeasure).Width(30); columns.Bound(p => p.Dimension.Length).Width(30); columns.Bound(p => p.Dimension.Width).Width(30); columns.Command(commands => commands.Edit().ButtonType(GridButtonType.ImageAndText)); }) .Pageable() .Scrollable(c => c.Height("375px")) .Sortable() )Controller
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using Telerik.Web.Mvc;namespace Test.App.MVC.Controllers{ [Authorize] public class HomeController : Csla.Web.Mvc.Controller { //This method is called for every button press (Add New, Insert, and Cancel) public ActionResult Index() { ViewBag.Message = "Welcome to BlueShip"; ControllerBase.State.ClearObjects(); Test.App.MVC.Models.ShipmentModel shipmentModel = new Test.App.MVC.Models.ShipmentModel(); shipmentModel.Shipment.ShipmentStatus = "New"; ControllerBase.State.Object = shipmentModel; ViewData.Model = shipmentModel; return View(); } [GridAction] public ActionResult SelectDefaultReferences() { try { Test.App.MVC.Models.ShipmentModel shipmentModel = (Test.App.MVC.Models.ShipmentModel)ControllerBase.State.Object; return View(new GridModel(shipmentModel.Shipment.ItemList)); } catch (Exception e) { ModelState.AddModelError(string.Empty, "Error occurred: " + e.Message); return PartialView("Error"); } } [AcceptVerbs(HttpVerbs.Post)]
[GridAction] public ActionResult SaveDefaultReferences(int id) { try { Test.App.Business.Shipment.Item item = new Business.Shipment.Item(); Test.App.MVC.Models.ShipmentModel shipmentModel = (Test.App.MVC.Models.ShipmentModel)ControllerBase.State.Object; shipmentModel.Shipment.ItemList.Remove(item); TryUpdateModel(item); shipmentModel.Shipment.ItemList.Add(item); return View(new GridModel(shipmentModel.Shipment.ItemList)); } catch (Exception e) { ModelState.AddModelError(string.Empty, "Error occurred: " + e.Message); return PartialView("Error"); } } [AcceptVerbs(HttpVerbs.Post)]
[GridAction] public ActionResult InsertDefaultReferences() { try { Test.App.Business.Shipment.Item item = new Business.Shipment.Item(); Test.App.MVC.Models.ShipmentModel shipmentModel = (Test.App.MVC.Models.ShipmentModel)ControllerBase.State.Object; TryUpdateModel(item); shipmentModel.Shipment.ItemList.Add(item); return View(new GridModel(shipmentModel.Shipment.ItemList)); } catch (Exception e) { return PartialView("Error"); } }}