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

MVC Extensions migration & route values

5 Answers 708 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Phil
Top achievements
Rank 1
Phil asked on 22 Mar 2013, 02:57 PM
We are in the process of migrating from the MVC Extensions to the Kendo MVC wrappers.

We are using Server-side binding on grids, and in the old MVC Extensions, the basic CRUD methods passed the datakey as a generic "id" parameter, regardless of the actual key field name.  In the Kendo wrappers it uses the actual key field name, e.g. orderID.  

e.g. our old code would be something like 
(View)
.DataKeys(dataKeys => dataKeys.Add(model => model.orderId))
(Controller)
public ActionResult Delete(int id) {}

It appears we have to change them to use the actual field name, e.g.
(View)
.DataSource(source => source.Server()
....Model(model =>{model.Id(o => o.OrderID);})  )        
(Controller)
public ActionResult Delete(int orderID){}

Is there a way for me to force it to pass the field name = "id" somehow, e.g. as a parameter on the DataSource .Action ?

Also, we were using  RouteData in some of our code to pass search values back & forth.  With the Kendo MVC wrappers, the RouteData is lost between the controller & view.

Maybe I'm missing some basic difference related to RouteMaps & Kendo MVC?

Thanks for your help.

5 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 26 Mar 2013, 12:06 PM
Hello Phil,

Changing the parameter name is not supported but the value can be send as "id" by adding it to the route values e.g.

.DataSource(dataSource => dataSource
    .Server()
    .Model(model =>
        {
            model.Id(p => p.MyID);               
        })
    .Update(update => update.Action("action", "constroller", new { id = Request.QueryString["MyID"] }))
I am not sure what is causing the problem with the RouteData. Could you provide the code you are using so I can check the setup? Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Phil
Top achievements
Rank 1
answered on 26 Mar 2013, 03:38 PM
Thanks.

For the Route Data, we had been passing search criteria back to the view using something like this in the controller:
 this.RouteData.Values.Add("clientId", clientId); 
which made the data available in the route values /query string so we had the search criteria available for paging, sorting, etc.   (We are using server binding.)

From what I could tell the Kendo script initializes the Route Values so that all that is passed back to the controller when paging, sorting, etc. is the grid parameters set by the script: sort, filter, etc. parameters.  So the values we had set were lost.

Meanwhile, we've changed our approach and are no longer using the route values but I am curious as to why this was changed between the old Telerik MVC extensions & Kendo.
0
Phil
Top achievements
Rank 1
answered on 26 Mar 2013, 04:26 PM
Hi,

One  more question:

Your suggestion for adding the id to the Update works fine, but the same approach does not work for Destroy.  Do you know what the different between Update and Destroy is?

Thanks.
0
Daniel
Telerik team
answered on 28 Mar 2013, 04:50 PM
Hi Phil,

Both the Kendo MVC Grid and the Telerik Extensions Grid use the same approach to construct the URL on the server but indeed there are some differences in how the Kendo Grid processes the request on the client. The URL to which the Grid navigates is constructed by using the serialized read url and the window.location but because the parameter added to the RouteData will not be found in neither one of them, it will be lost. I am sorry for the inconvenience caused. 

Regarding the destroy route value - it will not be sent with this approach because the ID will not be in the request values(a single request is used). Unfortunately there is not a straightforward way to send the ID with a different name in this case and I can only suggest to use a template to include the same markup with the ID added to the form URL:

@using Kendo.Mvc.Extensions;
@{
    var routeValues = ViewContext.Controller.GridRouteValues();
}
 
 ....
 
 columns.Template(@<text>
        @{
            routeValues["id"] = item.MyID;
        }
         <form action='@Url.Action("action", "controller", routeValues)' class="k-grid-actions" method="post">
            <div>
                <button class="k-button k-button-icontext k-grid-delete" type="submit">
                <span class="k-icon k-delete"></span>Delete</button>
            </div>
        </form>
     
    </text>);
Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Phil
Top achievements
Rank 1
answered on 28 Mar 2013, 10:24 PM
OK, thanks for the explanation.
Tags
Grid
Asked by
Phil
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Phil
Top achievements
Rank 1
Share this question
or