This question is locked. New answers and comments are not allowed.
Hi,
I'm trying to use the GridView component, but I've some problem. I'm basing myself on your example located on http://demos.telerik.com/aspnet-mvc/grid/editingajax
The problem is that when I click on any button, I don't get an ajax call but the page reloads to an inexistant page.
The model of my view contains a List<Product>() on which is bound the grid. Here is how is defined the product class
Here is how I'm defining the grid, we can see that I've ajax data binding:
Here is methods of my controller(named "Request" in "RequestController.cs")
But I'm getting html code generated, where you get javascript CData code.
What I've done wrong??
Thank you!
I'm trying to use the GridView component, but I've some problem. I'm basing myself on your example located on http://demos.telerik.com/aspnet-mvc/grid/editingajax
The problem is that when I click on any button, I don't get an ajax call but the page reloads to an inexistant page.
The model of my view contains a List<Product>() on which is bound the grid. Here is how is defined the product class
namespace DataModel{ [KnownType(typeof(Product))] public class Product { [ScaffoldColumn(false)] public int Id { get; set; } [DisplayName("Référence")] public String Reference { get; set; } [DisplayName("Description")] public String Description { get; set; } [DisplayName("Prix unitaire")] [DataType(DataType.Currency)] public Double UnitarPrice { get; set; } [Required] [DisplayName("Units in stock")] [DataType("Integer")] public int ProductCount { get; set; } }}Here is how I'm defining the grid, we can see that I've ajax data binding:
<div> @(Html.Telerik().Grid(Model.Products).Name("uxUnitsGrid") .DataKeys(keys => { keys.Add(p => p.Id); }) .ToolBar(commands => commands.Insert().ButtonType(GridButtonType.ImageAndText).ImageHtmlAttributes(new {style="margin-left:0"})) .DataBinding(dataBinding => { dataBinding.Ajax() .Select("_SelectAjaxEditing", "Request") .Insert("_InsertAjaxEditing", "Request") .Update("_SaveAjaxEditing", "Request") .Delete("_DeleteAjaxEditing", "Request"); }) .Columns( columns => { columns.Bound(p => p.Id).Hidden(true); columns.Bound(p => p.Reference).Title("Référence"); columns.Bound(p => p.Description).Title("Description"); columns.Bound(p => p.UnitarPrice).Title("Prix unitaire"); columns.Bound(p => p.ProductCount).Title("Nombre de produits"); columns.Command(commands => { commands.Edit().ButtonType(GridButtonType.ImageAndText); commands.Delete().ButtonType(GridButtonType.ImageAndText); }).Width(180).Title("Commandes"); } ) .Pageable() .Sortable() .Scrollable() .Editable(editing => editing.Mode(GridEditMode.InLine)) )</div>Here is methods of my controller(named "Request" in "RequestController.cs")
[HttpPost][Authorize]public ActionResult ManageRequest(RequestModel model){ System.Web.HttpContext.Current.Session["RequestModel"] = model; return View(model);}[Authorize]public ActionResult Index(){ return View();}[GridAction]public ActionResult _SelectAjaxEditing(){ return View(System.Web.HttpContext.Current.Session["RequestModel"]);}[AcceptVerbs(HttpVerbs.Post)][GridAction]public ActionResult _SaveAjaxEditing(int id){ Product product = ((RequestModel) System.Web.HttpContext.Current.Session["RequestModel"]).Products.Where(p => p.Id == id).First(); TryUpdateModel(product); return View(System.Web.HttpContext.Current.Session["RequestModel"]);}[AcceptVerbs(HttpVerbs.Post)][GridAction]public ActionResult _InsertAjaxEditing(){ //Create a new instance of the EditableProduct class. Product product = new Product(); //Perform model binding (fill the product properties and validate it). if (TryUpdateModel(product)) { //The model is valid - insert the product. List<Product> products = ((RequestModel) System.Web.HttpContext.Current.Session["RequestModel"]).Products; product.Id = ((RequestModel) System.Web.HttpContext.Current.Session["RequestModel"]).GetNewIndex(); products.Add(product); } //Rebind the grid return View(System.Web.HttpContext.Current.Session["RequestModel"]);}[AcceptVerbs(HttpVerbs.Post)][GridAction]public ActionResult _DeleteAjaxEditing(int id){ //Find a customer with ProductID equal to the id action parameter Product product = ((RequestModel)System.Web.HttpContext.Current.Session["RequestModel"]).Products.Where(p => p.Id == id).FirstOrDefault(); if (product != null) { //Delete the record ((RequestModel) System.Web.HttpContext.Current.Session["RequestModel"]).Products.Remove(product); } //Rebind the grid return View(System.Web.HttpContext.Current.Session["RequestModel"]);}But I'm getting html code generated, where you get javascript CData code.
What I've done wrong??
Thank you!