I have a Telerik grid query. The grid with delete action is working fine in FF and Crome. But in IE showing error 500. I put up break point at the starting point of action method. But its not reaching the action at all. Please tell me what's wrong with this query.
Query
#(Html.Telerik().Grid<Vibrant.Areas.ItemControl.Models.ViewModel>()
.Name("Temp").ClientEvents(e => e.OnLoad("SetFilterPosition").OnDataBinding("Grid_onDataBinding").OnRowDataBound("RowBound").OnDataBound("onDataBound"))
.DataKeys(d => { d.Add(a => a.Itemid).RouteKey("Id"); d.Add(a => a.CurrItemNo).RouteKey("ItemNo"); d.Add(a => a.CurrStatus).RouteKey("Status"); d.Add(a => a.CurrLocation).RouteKey("Location"); d.Add(a => a.CurrStart).RouteKey("Start"); d.Add(a => a.CurrEnd).RouteKey("End"); d.Add(a => a.Option).RouteKey("Option"); })
.ToolBar(commands => commands.Position(GridToolBarPosition.Bottom)
.Custom().ButtonType(GridButtonType.Text)
.HtmlAttributes(new { id = "export" })
.Text("Export to Excel")
.Action("ExportExcel", "WeedItem", new { page = 1, orderBy = "~", filter = "~" }))
.Columns(columns =>
{
columns.Bound(o => o.INo).Title("Item No");
columns.Bound(o => o.BTags).Title("Title");
columns.Bound(o => o.Sid).Title("Status");
//columns.Bound(o => o.Option).Title("Record Status");
columns.Command(commands =>
{
commands.Delete();
}).Width(80).Title("Action");
})
.Pageable(paging =>
paging.PageSize(10)
.Style(GridPagerStyles.NextPreviousAndDropDown | GridPagerStyles.Numeric)
.Position(GridPagerPosition.Bottom)
)
.DataBinding(dataBinding => dataBinding
.Ajax().Select("post", "WeedItem").Delete("DeleteTempData", "WeedItem"))
.Sortable()
.Filterable()
.Groupable()
)
Controller
[GridAction]
public ActionResult DeleteTempData(int Id)
{
var model = ......
...... ;
return View(new GridModel(model));
}
Thanks
The view is returned at the end of your action method. If you cannot hit a debug point at the start of action method, then the problem is not in your view (or grid). 500 is an internal server error, I'd double check the URL you're trying to navigate to and custom errors off in your web.config.
<configuration>
<system.web>
<customErrors mode="Off"/>
...
</system.web>
...
</configuration>
Related
So I've got a grid that I believe is all set up correctly. I've confirmed that the data is coming through, and I've even checked that the AJAX call returns a success with the "ToDataSourceResult" JSON data.
Unfortunately, the only problem is that the data doesn't display. This seems to only be an issue on read, as update, create and delete all work. Just can't retrieve the list of all items afterwards.
My controller action looks like this:
public IActionResult Blog_Read([DataSourceRequest] DataSourceRequest request)
{
var blogs = _blogService.GetPosts().Select(post => new BlogPostModel
{
Id = post.Id,
Title = post.Title,
Author = post.Author,
ShortDescription = post.ShortDescription,
Contents = post.Contents,
LastSaved = post.LastSaved,
Published = post.Published,
PublishedOn = post.PublishedOn
});
var result = blogs.ToDataSourceResult(request);
return Json(result);
}
And my Grid View looks like this:
#(Html.Kendo().Grid<BlogPostModel>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.Title);
columns.Bound(p => p.Author).Width(120);
columns.Bound(p => p.LastSaved).Width(120);
columns.Bound(p => p.Published).Width(120);
columns.Command(command => { command.Edit(); command.Destroy(); }).Width(250);
})
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.PopUp))
.Pageable()
.Sortable()
.Scrollable()
.HtmlAttributes(new { style= "height:600px;"})
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Events(events => events.Error("error_handler"))
.Model(model => model.Id(p => p.Id))
.Create(update => update.Action("Blog_Create", "BlogAdmin"))
.Read(read => read.Action("Blog_Read", "BlogAdmin"))
.Update(update => update.Action("Blog_Update", "BlogAdmin"))
.Destroy(update => update.Action("Blog_Delete", "BlogAdmin"))
)
.Deferred()
)
The correct JSON is returned, no javascript errors in the console, so I'm a little confused as to what this could be. Any help would be greatly appreciated.
I solved this by adding
services.AddMvc().AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());
to my Startup.cs ConfigureServices method.
I am having an issue where the READ operation for the Kendo Grid does not get invoked and hence the grid does not populate any data. I have followed these links
http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/troubleshooting#the-ajax-bound-grid-does-not-populate
Kendo UI Grid is not calling READ method
However the issue still exists.
/// CS File
public ActionResult GetItemsHome([DataSourceRequest] DataSourceRequest request , int page)
{
List<CustomItem> lst = new List<CustomItem>();
return Json(lst.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
///cs html file
#(Html.Kendo().Grid<CustomItem>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(o => o.No).Width("15%");
columns.Bound(o => o.ShortDesc).Width("15%");
columns.Bound(o => o.Category).Width("6%");
})
.Sortable()
.Pageable(p=>p.Refresh(true))
.Filterable()
.Scrollable()
.Editable(edit => edit.DisplayDeleteConfirmation("Are You Sure To Delete This ").Mode(GridEditMode.PopUp))
.ColumnMenu(col=>col.Sortable(false))
.Groupable()
.ToolBar(toolbar => toolbar.Create())
.Resizable(resize => resize.Columns(true))
.Reorderable(reorder => reorder.Columns(true))
//.ClientDetailTemplateId("template")
.HtmlAttributes(new { style = "height:430px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(6)
.Read(read => read.Action("GetItemsHome", "det"))
.Model(model => {
model.Id(p => p.ID);
})
.Create(update => update.Action("EditingInline_Create", "det"))
// .Read(read => read.Action("EditingInline_Read", "Default1"))
.Update(update => update.Action("EditingInline_Update", "det"))
.Destroy(update => update.Action("EditingInline_Destroy", "det"))
)
)
the order in which the JS is loaded
Any ideas ?
Thanks
Your action GetItemsHome([DataSourceRequest] DataSourceRequest request , int page) requires page (non-null value) to be passed. You have 3 options:
Delete this argument (this makes sense since request contains everything you want)
Supply it like: .Read(read => read.Action("GetItemsHome", "det", new { page = 10}))
Make it nullable like: int? page
EDIT: After following any of above, return some data from controller action (I am creating some arbitrary data, you may return it from DB instead) to fill up your grid. Something like:
public ActionResult GetItemsHome([DataSourceRequest] DataSourceRequest request , int? page)
{
//List<CustomItem> lst = new List<CustomItem>();
// Dummy data
var data = new [] { new CustomItem(){ No = 1, ShortDesc = "xyz", Category = "abc"},
new CustomItem(){ No = 2, ShortDesc = "xyz", Category = "abc"} };
return Json(data.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
If your controller and action names are spelled correctly in view, above code should work.
Some possibilities, if your function is not being called:
If your ActionResult Index() function is doing some other operations instead of simply return View() and exiting, it's possible your GetItemsHome() function may not be called - I had this issue once.
Try just naming the function "Read" instead of "GetItemsHome".
Does your controller have any other functions (i.e. Update, Destroy)? I would comment them out, in case there are syntax issues in them that are causing the issue.
"det", I hope, is the name of your controller.
Why pass in the extra page parameter at all? Try it without it, and use a public variable in your model to hold that value.
I have Kendo Grid with delete command. When I click delete and then click "save change" on the left top of grid, real data is not sent to server. data has key/create date/other fields. I used Odata service. In debug mode, key = 0 and create date = 1/1/0001. Anyone got a clue what is happening here?
#(Html.Kendo().Grid<OData.proxySvc.table1>()
.Name("MyGrid")
.Columns(columns =>
{
columns.Bound(f => f.key).Visible(false);
columns.Bound(f => f.UserName).Title("Name");
columns.Command(command => {
command.Destroy();
}).Title("Action").Width(90);
})
.ToolBar(toolbar =>
{
toolbar.Save();
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Sortable()
.Scrollable(s => s.Height("100px"))
.Filterable()
.DataSource(ds => ds
.Ajax()
.Batch(true)
.ServerOperation(false)
.Model(model => model.Id(p => p.key))
.Destroy("Delete","Home")
))
in control file, there is action:
// no [Httppost] attributes. if [HttpPost] attributes exist, no event fire
public ActionResult Delete([DataSourceRequest]DataSourceRequest request,
[Bind(Prefix = "models")]IEnumerable<table1> tbl1)
{
var context = CreateOdataServiceContext();
foreach (var t1 in tbl1)
{
var x = context.table1.Where(r => r.key == t1.key).FirstOrDefault();
if (x!=null)
{
context.DeleteObject(x);
context.SaveChanges();
}
}
}
I have a telerik grid in my index.cshtml and i created a custom Edit Command in my Grid. I want that whenever i click on edit i want to pass every column value to a PopUp window i created and assign those values to text boxes inside PopUp Window.
My Grid looks like as follows
#(Html.Telerik().Grid<POModel>().Name("PurchaseOrders")
.DataKeys(keys => keys.Add(o => o.WorkOrderPaymentID))
.Columns(columns =>
{
columns.Bound(o => o.SuppliersInvoiceNumber).HeaderTemplate("<div>Invoice Number</div>") ;
columns.Bound(o => o.PONumber).HeaderTemplate("<div>PO Number</div>").ReadOnly().Width(215);
columns.Bound(o => o.VendorName).HeaderTemplate("<div>Vendor Name</div>").ReadOnly();
columns.Bound(o => o.AmountPaidToSupplier).HeaderTemplate("<div>Total PO Amount</div>").Format("{0:c}").ReadOnly();
columns.Command(commands => commands
.Custom("Edit")
.Text("Edit")
.SendState(false)
.DataRouteValues(route =>
{
route.Add(o => o.SuppliersInvoiceNumber).RouteKey("InvoiceNumber");
route.Add(o => o.PONumber).RouteKey("PONumber");
route.Add(o => o.VendorName).RouteKey("VendorName");
route.Add(o => o.AmountPaidToSupplier).RouteKey("AmountPaid");
})
.Ajax(true)
.Action("editPOList", "PurchaseOrder", new { invoiceID = Model.selectedInvoiceID }));
})
.DataBinding(dataBinding => dataBinding.Ajax().Select("getPOList", "PurchaseOrder", new { invoiceID = Model.selectedInvoiceID }))
.Scrollable()
.Editable(editing => editing.Enabled(true))
.Sortable() )
What my Grid Action for Edit should look like if i want to pass all the column values to PopUp Window??
Most probably the default MVC Model Binder will successfully extract the Route values so you can add POModel argument to your action method signature.
public ActionResult editPOList(POModel model)
{
//...
}
I have an MVC 3 Razor Telerik grid. When the Update for an Edit button is clicked, the proper Controller is executed and the TryUpdateModel statement is performed.
I purposely put in some text that I know whould casuse an error. The TryUpdateModel returns false (which is expected in this circumstance) and then executes the return View(); statement.
However, I get back a modal dialog box that says "The requested URL returned a 500 error". If I click the modal dialog and look on the grid, no validation msg appears.
If I am not using a Telerik grid with just input boxes, the validation msg appears fine from my DataAnnotations that reside inside my Model.
What am I doing incorrectly?
Here is my View:
#model Telerik.Web.Mvc.GridModel<YeagerTech.YeagerTechWcfService.Customer>
#{
ViewBag.Title = "Customer Index";
}
<h2>
Customer Index</h2>
#( Html.Telerik().Grid<YeagerTech.YeagerTechWcfService.Customer>(Model.Data)
.Name("Customers")
.DataKeys(dataKeys => dataKeys.Add(o => o.CustomerID)
.RouteKey("CustomerID"))
.ToolBar(commands => commands.Insert().ButtonType(GridButtonType.Text).ImageHtmlAttributes(new { style = "margin-left:0" }))
.Columns(columns =>
{
columns.Bound(o => o.CustomerID).Hidden(true);
columns.Command(commands =>
{
commands.Edit().ButtonType(GridButtonType.Text);
}).Width(200).Title("Command");
columns.Bound(o => o.Email).Width(200);
columns.Bound(o => o.Company).Width(200);
columns.Bound(o => o.FirstName).Width(100).Title("FName");
columns.Bound(o => o.LastName).Width(100).Title("LName");
columns.Bound(o => o.Address1).Width(200).Title("Addr1");
columns.Bound(o => o.Address2).Width(100).Title("Addr2");
columns.Bound(o => o.City).Width(100);
columns.Bound(o => o.State).Width(40).Title("ST");
columns.Bound(o => o.Zip).Width(60);
//columns.Bound(o => o.HomePhone).Width(120);
//columns.Bound(o => o.CellPhone).Width(120);
//columns.Bound(o => o.Website).Width(100);
//columns.Bound(o => o.IMAddress).Width(100);
//columns.Bound(o => o.CreatedDate).Format("{0:MM/dd/yyyy}").ReadOnly(true).Width(120);
//columns.Bound(o => o.UpdatedDate).Format("{0:MM/dd/yyyy}").ReadOnly(true).Width(120);
}).DataBinding(dataBinding =>
dataBinding.Ajax()
.Insert("_InsertAjaxEditing", "Customer")
.Update("_SaveAjaxEditing", "Customer"))
.Editable(editing => editing.Mode(GridEditMode.InLine))
.Pageable()
.Sortable()
.Scrollable()
)
Here is my Controller:
[HttpPost]
[GridAction]
public ActionResult _SaveAjaxEditing(YeagerTechWcfService.Customer customer)
{
CustomerValidate custValidate = new CustomerValidate();
custValidate.CustomerID = customer.CustomerID;
custValidate.Email = customer.Email;
custValidate.Company = customer.Company;
custValidate.FirstName = customer.FirstName;
custValidate.LastName = customer.LastName;
custValidate.Address1 = customer.Address1;
custValidate.Address2 = customer.Address2;
custValidate.City = customer.City;
custValidate.State = customer.State;
custValidate.Zip = customer.Zip;
custValidate.HomePhone = customer.HomePhone;
custValidate.CellPhone = customer.CellPhone;
custValidate.Website = customer.Website;
custValidate.IMAddress = customer.IMAddress;
if (TryUpdateModel(custValidate))
{
try
{
db.EditCustomer(customer);
TempData["ErrCode"] = "Customer successfully updated.";
return RedirectToAction("Index", "Home");
}
catch (Exception ex)
{
TempData["ErrCode"] = "CustErr";
ViewBag.Error = ex.Message;
return View();
}
}
else
return View();
}