In View return parameter "orderid", but control can not get this parameter value! it is value always equal zero.
View:
<%= Html.Telerik().Grid<Demo_MasterDetail.Models.Order_Details>() .Name("Grid") .DataKeys(keys => keys.Add(c => c.ProductID)) .ToolBar(commands => commands.Insert().ButtonType(GridButtonType.Text).ImageHtmlAttributes(new { style = "margin-left:0" })) .DataBinding(dataBinding => { dataBinding.Ajax() .Select("_SelectAjaxEditing", "Home", new { orderid = Model.orders.OrderID }) .Insert("_InsertAjaxEditing", "Home", new { orderid = 99999 }) // <--------------- parameter .Update("_UpdatejaxEditing", "Home", new { orderid = Model.orders.OrderID }) .Delete("_DeleteAjaxEditing", "Home", new { orderid = Model.orders.OrderID }); }) .Columns(columns => { columns.Bound(o => o.OrderID).Width(80); columns.Bound(o => o.ProductID).Width(80); columns.Bound(o => o.UnitPrice).Width(80).Format("{0:N}").HtmlAttributes(new { style = "text-align: right" }); columns.Bound(o => o.Quantity).Width(80).Format("{0:N}").HtmlAttributes(new { style = "text-align: right" }); columns.Bound(o => o.Discount).Width(80); columns.Command(commands => { commands.Edit().ButtonType(GridButtonType.Text); commands.Delete().ButtonType(GridButtonType.Text); }).Width(180).Title("Commands"); }) .Pageable() .Editable(editing => editing.Mode(GridEditMode.InLine)) .Sortable() .Scrollable(scrolling => scrolling.Height(350)) %> controller:
[HttpPost] [GridAction] public ActionResult _InsertAjaxEditing(int orderid) // <----- orderid always = 0 { Order_Details tmporderdetails = new Order_Details(); TryUpdateModel(tmporderdetails); _myDataRepository.Insert(tmporderdetails); return View(new GridModel(_myDataRepository.All(orderid))); } 8 Answers, 1 is accepted
Did you find a solution to this problem? I am trying to do the same, but failing like you.
Let me know if you found a solution or workaround.
Mark.
Same issue for me !
Please, help us !
I have found a workaround that I will use until Telerik is going to finally provide an answer or a solution. This would work with GridEditMode.PopUp - didn't explored the other options.
My scenario is as following: I use TreeView to select a master entity then in a Grid I insert detail records with Ajax.
I have created an EditorTemplate for my slave entity. In that template I added a hidden field for the MasterId (which is also property of the slave entity)
On TreeView I handle onSelected client-side event (if you use Grid for the master records there exists a similar onRowSelect client event), on this even I store into a globa variable the id of the master record.
I handle the client event onSave of the details grid, and there I have the opportunity to set manually the MasterId using
e.values["MasterId"] = gMasterId;
My Insert action in controller will not receive any parameter, the id will be populated directly by TryUpdateModel from the hidden's field value.I feel that this is not how it shall work, but I was not able to find another way. Hopfully Telerik will provide soon a solution for this annoying issue.
A more elegant alternative would have been if in the onSave() Grid client event I it would have been possible to extend the e.data with the masterId parameter, like I do in onDataBinding event
function onDataBinding(e) {
e.data = $.extend(e.data, { masteId: gMasterId });
}
Now if you extend e.data in the onSave event .. it is just ignored. If this would work then no need for EditTemplate & hidden Fields and would have work with all GridEditModes, all most nice.
The recommended way to send additional values to the server is via the values event argument of the OnSave event. I think it is actually the same approach as e.data when using OnDataBinding - just the arguments name is different.
Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
I have checked now and it works with passing it via "values" event parameter. I had two misleading assumptions:
1. I was assuming that e.data is used for action's parametes and e.values for the fields that gets posted to the server and populated by TryUpdateModel.
2. I found only samples where in the onSave event, were only manipulation of existing fields (e.g. provide default values) that's why I tought I will need a hidden field for it.
using OnSave and e.Values["MasterId"] = id... will propagate the parameter into TryUpdateMode, but also into the action's parameter if a proper route is available.
Thanks for clarifying this for us.
Vasile
I have seen/had this problem before & it drove me NUTS!
I think the problem is due to a binding conflict.
Place a break on the first line of the _InsertAjaxEditing Action.
If you look at the Request QueryString (in the immediate window: ?Request.QueryString) the parameter should be there correctly: orderid=9999.
But there is also an OrderID on the form. In the immediate window: ?HttpContext.Request.Form["OrderID"] the value is zero.
I think that when the Action's parameters are bound, MVC is using the OrderID in the form (ignoring the upper case letters). Apparently, the binder is not ‘case’ sensitive.
I have always fixed this by changing the action parameter name to one not used in the form or model.
Try setting the ajax route value as: .Insert("_InsertAjaxEditing", "Home", new { idOrder = 99999 })
and define the action: public ActionResult _InsertAjaxEditing(int idOrder)
This has worked for me.