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

[Solved] Grid Binding and AntiForgery Tokens

5 Answers 200 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.
Chris
Top achievements
Rank 1
Chris asked on 20 Jul 2011, 05:33 PM
  I'm trying to set things up with my grid such that every action that every ajax post will include an antiforgery token.  My gird is set up like so:

@(Html.Telerik().Grid(Model)
            .Name("Folks")
            .Sortable(x => x.SortMode(GridSortMode.SingleColumn))
            .PrefixUrlParameters(false)
            .Footer(true)
            .Pageable(x => x.PageSize(25).Total((int)ViewData["total"]))
            .DataBinding(dataBinding => dataBinding.Ajax())
            .Columns(columns =>
            {
                columns.Bound(o => o.ParticipantFirstName).Width(120).Title("First Name");
                columns.Bound(o => o.ParticipantLastName).Width(120).Title("Last Name");
            })
            .Selectable()
            .ClientEvents(events =>
            {
                events.OnDataBinding("Test");
            })
    )

The handler for OnDataBinding (Test) looks like so:
<script type="text/javascript">
    function Test(e) {
        var valTokenValue = $("input[name=__RequestVerificationToken]").val();
        e.data = { __RequestVerificationToken: valTokenValue };
    }
</script>

I thought the argument (e) had a property called data which accepted a dictionary of values.  However, FireBug keeps complaining saying that data is undefined.  Any ideas how I can include the token with every request?

5 Answers, 1 is accepted

Sort by
0
Chris
Top achievements
Rank 1
answered on 20 Jul 2011, 06:19 PM
Also, I should mention that I'm using version 2011.Q2.712 with jquery version 1.5.1.
0
SEAN
Top achievements
Rank 1
answered on 21 Jul 2011, 03:19 AM
You'll need to put the anti-forgery token into your page - use the @Html.AntiForgeryToken() helper, then your code should work because the helper will put a hidden field named __RequestVerificationToken with the token value into your page.

0
Atanas Korchev
Telerik team
answered on 21 Jul 2011, 10:09 AM
Hello,

 This may happen because your grid is not properly configured for ajax binding:

.DataBinding(dataBinding => dataBinding.Ajax())

You should specify an action method and controller.

Find attached a working sample project.

Regards,

Atanas Korchev
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
John DeVight
Top achievements
Rank 1
answered on 29 Dec 2011, 09:08 PM
Take a look at this article: Implementing the Anti-Forgery Token with the Telerik MVC Grid

Regards,

John DeVight
0
Steven
Top achievements
Rank 1
answered on 26 Mar 2013, 11:43 PM
Tried you suggestion in my code and as usual you suggestions does not work.
Tags
Grid
Asked by
Chris
Top achievements
Rank 1
Answers by
Chris
Top achievements
Rank 1
SEAN
Top achievements
Rank 1
Atanas Korchev
Telerik team
John DeVight
Top achievements
Rank 1
Steven
Top achievements
Rank 1
Share this question
or