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

[Solved] Edit Button misses route parameter

2 Answers 99 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.
Ronald
Top achievements
Rank 1
Ronald asked on 23 May 2011, 01:57 PM
Hi there,

In the following grid I am missing a route parameter in the URL used by the Edit-button in the grid. The route parameter appears after post-actions like Insert, but when the grid is rendered when loading the page, it does not work.

Situation: depending on a choosen value from a dropdown list box, the grid is filled with items in a certain context (the choosen value from the dropdown listbox). The .aspx file looks like this:

<table border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td>
                Please select a set name to maintain the sentences for 
            </td>
            <td>
                <%using (Html.BeginForm("Index", "FooSentence", FormMethod.Post, new { NoDialog = true} ))
                {
                    var selectList = new SelectList(ViewBag.DataSections, "Id", "Name", ViewBag.DataSectionId);
                %>
                <%: Html.DropDownList("context", selectList) %>
            </td>
            <td>
                <button class="t-button t-state-default" type="submit">Apply</button>
            </td>
                <%}%>
        </tr>
    </table>
<%: Html.ValidationSummary()%>
<%
    Html.Telerik().Grid(Model)
        .Name("RefFooSentence")
        .DataKeys(keys => keys.Add(key => key.Id))
        .DataBinding(databinding => databinding.Server()
                                        .Insert("Insert", "FooSentence", new { Context = ViewBag.DataSectionId })
                                        .Update("Edit", "FooSentence", new { Context = ViewBag.DataSectionId })
                                        .Delete("Delete", "FooSentence", new { context = ViewBag.DataSectionId })
        )
        .Editable(editable => editable.Mode(GridEditMode.InLine)
        )
        .Columns(columns =>
                    {
                        columns.Bound(c => c.Sentence);
                        columns.Command(cmd =>
                        {
                            cmd.Edit();
                            cmd.Delete();
                        }).Width(180).Title("Commands");
                    })
        .ToolBar(toolbar =>
                        toolbar.Custom()
                            .Text(string.Format("Add new {0}", ViewBag.DataSectionName ?? ""))
                            .Action("Index", "FooSentence", new RouteValueDictionary
                                                    {
                                                        {"RefFooSentence-Mode", "insert"}, // Necessary for Telerik Grid to indicate its rendering... 
                                                        {"Context", ViewBag.DataSectionId}
                                                    })
        )
        .Render();
  %>   

The value of ViewBag.DataSectionId is always known. When the grid is rendered, the URL of the Edit button is this:
/RefData/FooSentence/Index/1?RefFooSentence-mode=edit , and the URL of the Delete button is this:
/RefData/FooSentence/Delete/1?context=2 . The difference is that the Delete button has the route parameter context, but the Edit button does not.

When I hit Insert and Cancel, or Insert and Save, the URL of the Edit button is different:
/RefData/FooSentence/Index/1?Context=2&RefFooSentence-mode=edit 
and the Delete button still has the same URL as before.

Is this a bug, or am I doing something wrong? I'm working with version 2011.1.322.340 of Telerik.Web.MVC.dll.
Then,

2 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 24 May 2011, 08:06 AM
Hi Ronald,

 Could you try specifying the Select databind setting as well? The grid is using that when going in edit mode. Udate is used when saving a modified record.

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
0
Ronald
Top achievements
Rank 1
answered on 24 May 2011, 08:50 AM
Thanks Atanas!

This solved the problem.
Tags
Grid
Asked by
Ronald
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Ronald
Top achievements
Rank 1
Share this question
or