This question is locked. New answers and comments are not allowed.
Hi, I have some linked tables from which I want to display one table records, it is working on one of the table, but not working on another one.
My code for Ajax Binding is as follows:
[[ View ]]
[[ Controller ]]
[[SessionStockRepository]]
But After this Im getting the Following Error on View
"Error: The requested URL returned 500 - Internal Server Error"
I also have attached the snapshot of screen.
My code for Ajax Binding is as follows:
[[ View ]]
<%= Html.Telerik().Grid<PaceTelerik.Models.Stock>() .Name("Grid") .DataKeys(keys => { keys.Add(p => p.Stock_ID); }) .ToolBar(commands => { commands.Insert().ButtonType(GridButtonType.ImageAndText).ImageHtmlAttributes(new { style = "margin-left:0" }); }) .DataBinding(dataBinding => { dataBinding.Ajax().OperationMode(GridOperationMode.Server) .Select("_SelectAjaxEditing", "Stock") .Insert("_InsertAjaxEditing", "Stock") .Update("_SaveAjaxEditing", "Stock") .Delete("_DeleteAjaxEditing", "Stock"); }) .Columns(columns => { columns.Bound(p => p.Description).Width(210); columns.Command(commands => { commands.Edit().ButtonType(GridButtonType.Text); commands.Delete().ButtonType(GridButtonType.Text); }).Width(200).Title("Commands"); }) .Editable(editing => editing .Mode(GridEditMode.PopUp)) .Pageable() .Scrollable() .Sortable()%>[[ Controller ]]
//Ajax Grid Editing Code// [GridAction] public ActionResult _SelectAjaxEditing() { return View(new GridModel(SessionStockRepository.All())); } [AcceptVerbs(HttpVerbs.Post)] // [CultureAwareAction] [GridAction] public ActionResult _SaveAjaxEditing(int id) { Stock stock = SessionStockRepository.One(p => p.Stock_ID == id); TryUpdateModel(stock); SessionStockRepository.Update(stock); return View(new GridModel(SessionStockRepository.All())); } [AcceptVerbs(HttpVerbs.Post)] // [CultureAwareAction] [GridAction] public ActionResult _InsertAjaxEditing() { //Create a new instance of the Editablestock class. Stock stock = new Stock(); //Perform model binding (fill the stock properties and validate it). if (TryUpdateModel(stock)) { //The model is valid - insert the stock. SessionStockRepository.Insert(stock); } //Rebind the grid return View(new GridModel(SessionStockRepository.All())); } [AcceptVerbs(HttpVerbs.Post)] [GridAction] public ActionResult _DeleteAjaxEditing(int id) { //Find a customer with stockID equal to the id action parameter Stock stock = SessionStockRepository.One(p => p.Stock_ID == id); if (stock != null) { //Delete the record SessionStockRepository.Delete(stock); } //Rebind the grid return View(new GridModel(SessionStockRepository.All())); }[[SessionStockRepository]]
public static class SessionStockRepository { public static IList<Stock> All() { IList<Stock> result = (IList<Stock>)HttpContext.Current.Session["Stocks"]; if (result == null) { B4GEntities_Procurement db = new B4GEntities_Procurement(); var query = db.Stocks.Include("StockCategory").Include("StockType").Include("Supplier"); HttpContext.Current.Session["Stocks"] = result = (from product in query select product) .ToList(); } return result; } public static Stock One(Func<Stock, bool> predicate) { return All().Where(predicate).FirstOrDefault(); } public static void Insert(Stock product) { product.Stock_ID = All().OrderByDescending(p => p.Stock_ID).First().Stock_ID + 1; All().Insert(0, product); } public static void Update(Stock product) { Stock target = One(p => p.Stock_ID == product.Stock_ID); if (target != null) { target.Description = product.Description; target.CurrentStockLevel = product.CurrentStockLevel; } } public static void Delete(Stock product) { Stock target = One(p => p.Stock_ID == product.Stock_ID); if (target != null) { All().Remove(target); } }But After this Im getting the Following Error on View
"Error: The requested URL returned 500 - Internal Server Error"
I also have attached the snapshot of screen.