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

[Solved] AntiforgeryToken On Insert

9 Answers 222 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.
murali
Top achievements
Rank 1
murali asked on 12 May 2011, 03:34 AM
Hello All,

I am having a simple grid with a ajax binding and one of the column is a drop down. When I try to insert a new record in the grid, the AntiforgeryToken is not passed to the controller. I am setting token on OnDataBinding event.

I am running on version 2011.1.315. Any help is greatly appreciated. I even tried couple of alternatives like tried to add an input control to the form on onsave event, this didn't help either, I don't know how to add the token to e.values on onsave event.

Any suggestions?

Thank you,
mm

9 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 12 May 2011, 07:16 AM
Hi mm,

 I created a sample project showing how to do send the antiforgery token via the OnSave event. Here is the relevant code:

<%: Html.AntiForgeryToken() %>
 
<%: Html.Telerik().Grid<GridAntiForgeryToken.Models.Customer>()
        .Name("Grid")
        .DataKeys(keys => keys.Add(c => c.ID))
        .Columns(columns =>
            {
                columns.Bound(c => c.ID).ReadOnly().Width(100);
                columns.Bound(c => c.Name);
                columns.Command(c => c.Edit()).Width(200);
            })
        .ClientEvents(e => e.OnSave("onSave"))
        .DataBinding(dataBinding => dataBinding.Ajax().Select("Select", "Home").Update("Update", "Home"))
%>
 
<script>
function onSave(e) {
    // anything added to e.values will be submitted to the server
    e.values["__RequestVerificationToken"] = $("input[name=__RequestVerificationToken]").val();
}
</script>

Kind 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
murali
Top achievements
Rank 1
answered on 12 May 2011, 08:53 PM
That's cool Atanas, that worked like a charm, but now I am having the same issue onDelete, how can I pass the AntiforgeryToken on a delete.

Thank you,
mm
0
Rosen
Telerik team
answered on 13 May 2011, 07:57 AM
Hi mm,

Unfortunately in its current implementation it is not possible to pass additional parameters through grid's delete client-side event. However, we were able to address this limitation and this will be possible with the next internal build.
Meanwhile, I have attached a modified version of telerik.grid.editing.js file for your convenience. I have also updated you telerik points.

Regards,
Rosen
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
murali
Top achievements
Rank 1
answered on 13 May 2011, 05:17 PM
Rosen, I tried your fix, but that didn't help, I also tried by adding the token to values on OnDelete event, but that didn't help either.

I just replaced the script file you sent me, did I miss anything.

Thank you for your help.

Murali.
0
Rosen
Telerik team
answered on 16 May 2011, 07:04 AM
Hi mm,

I have attached a modified version of the sample my colleague Atanas provided. Please give it a spin, maybe I'm missing something obvious. 

Regards,
Rosen
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
murali
Top achievements
Rank 1
answered on 24 May 2011, 04:35 AM
Hello Rosen,

I have tried version 414 and the patch you have sent me, unfortunately I am not able to run your sample project as it is MVC3, I get the following error. 

Cannot set property '__RequestVerificationToken' of undefined
I have looked at the files from your sample and copies the files over, but still get the same error, when I step through the debugger I don't see values property on e.

Any help is greatly appreciated.

Thank you,
mm
0
Atanas Korchev
Telerik team
answered on 24 May 2011, 06:49 AM
Hello mm,

 This means that the upgrade was not properly done. Please check this help article which outlines the required steps.

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
murali
Top achievements
Rank 1
answered on 24 May 2011, 05:17 PM
Hello Atanas,

I have gone through the steps again, and still have no luck.
All other features of the grid, tab and other Telerik components are working so I don't think I messed anything up with the upgrade. 

Thank you,
Murali.
0
Atanas Korchev
Telerik team
answered on 25 May 2011, 05:59 AM
Hi murali,

 Provided that the last sample project which we attached works as expected I am not sure what went wrong. Did you replace the telerik.grid.editing.min.js file with the one attached previously? It seems you have not.

 We have also included this fix in our latest internal build which you can download and try.

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
Tags
Grid
Asked by
murali
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
murali
Top achievements
Rank 1
Rosen
Telerik team
Share this question
or