This is a migrated thread and some comments may be shown as answers.

[Solved] BUG - RouteKey not being applied on .Insert with latest release

3 Answers 30 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jon Baron
Top achievements
Rank 1
Jon Baron asked on 17 Oct 2011, 09:20 PM
It is working fine on all other events.

Just within .Insert, the value is still being passed with a variable name of 'id'. No matter if RouteKey is applied to the datakey or not.

Thanks!

3 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 18 Oct 2011, 09:25 AM
Hi Jon Baron,

I'm afraid that I'm unable to recreate such behavior locally. Therefore, it will be appreciated if you could provide a bit more details about your scenario and implementation, small sample demonstrating the issue will be great. 

All the best,
Rosen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Jon Baron
Top achievements
Rank 1
answered on 18 Oct 2011, 02:54 PM
Sure, it's an AJAX bound grid.

Grid (in View):
@(Html.Telerik().Grid<ViewModel>()
                            .Name("gStatus")
                            .DataKeys(keys =>
                            {
                                keys.Add(fs => fs.ID);
                                keys.Add(fs => fs.Name).RouteKey("Name");                                                            
                            })
                            .ToolBar(commands => commands.Insert().ButtonType(GridButtonType.ImageAndText).ImageHtmlAttributes(new
                            {
                                style =
                                  "margin-left:0"
                            }))
                            .DataBinding(dataBinding =>
                            {
                                dataBinding.Ajax()
                                    .Select("Edit", "Personnel")
                                    .Insert("Insert", "Personnel")
                                    .Update("Save", "Personnel")
                                    .Delete("Delete", "Personnel");
                            })
                            .Columns(columns =>
                            {
                                columns.Bound(fs => fs.EmployeeID).Hidden(true);
                                columns.Command(commands =>
                                {
                                    commands.Edit().ButtonType(GridButtonType.Image);
                                    commands.Delete().ButtonType(GridButtonType.Image);
                                }).Width(100);
                                columns.Bound(fs => fs.Status).Title("Status");
                                columns.Bound(fs => fs.StatusID).Hidden(true);
                                columns.Bound(fs => fs.BeginDate).Width(100).Title("Start Date").Format("{0:MM/dd/yyyy}");
                                columns.Bound(fs => fs.FinalDate).Width(100).Title("End Date").Format("{0:MM/dd/yyyy}");
                                columns.Bound(fs => fs.LocationID).Hidden(true);
                                columns.Bound(fs => fs.Location).Width(200).Title("Status Location")
                                    .EditorTemplateName("Locations").Width(190);
                            })
                            .Pageable(paging =>
                                paging.PageSize(25))
                            .ClientEvents(events => events
                                .OnEdit("onEdit"))
)

Controller:
[AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult Insert(Status fs, string id, string Name)
        {
            // Bind the model with validation
            if (TryUpdateModel(fs, properties))
            {
                //The model is valid
                px.Update(fs);
            }

            // Return an AJAX view of this
            return View(new GridModel(px.GetStatus(Name)));
        }

So in the above Insert method, the string 'Name' is empty, and the  keys.Add(fs => fs.Name).RouteKey("Name");          is going into the string 'id'. keys.Add(fs => fs.ID); cannot be found.

As a result, it's not only confusing but it's giving a ModelState error, the reason is because the string 'Name' is getting translated into the int 'ID' field.

Again, this works fine on all 3 other events (Update, Select and Delete). No model errors, RouteKey properly coming across; I can acesss the unsigned key as 'id' and my signed key as 'Name'.

My database logic is in the 'px' Model but there's no reason to display that now as the result of this error prevents the Insert event from passing Model validation and dropping into the 'px' Model.

I am using Editor templates for dropdowns when in Edit mode, there is a javascript function tied to the onEdit client event to bind the dropdowns to properly selectedValues.

Please let me know if you need any more info on this.

One thing to note, it was working perfectly when the datakeys were both Int types. I only received the bug when switching the 2nd datakey to a string type.
0
Jon Baron
Top achievements
Rank 1
answered on 18 Oct 2011, 06:54 PM
Well,

Maybe it's not so much a bug. Has to deal with ModelState and using a non-PK field as the main id for all requests.

In short, the data doesn't exist because it's onInsert.

I simply removed the model binding in the Controller (for Insert only), removed passing a modelType to the controller, and just passed FormCollection from View -> Controller -> Model
Tags
Grid
Asked by
Jon Baron
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Jon Baron
Top achievements
Rank 1
Share this question
or