Question

I have come across implementing Anti forgery token for a POST method when its an ajax call,the couple of things I do here are

[1]Include[ValidateAntiForgeryToken] attribute for my POST controller method.

[2]Change $.ajax call to $.ajaxAntiForgery in my js.

Similarly I have a telerik upload control where I trigger the controller method from cshtml(instead of an ajax call)- cshtml code snippet below

@{ var upload = @Html.Telerik().Upload()
                .Name("attachments")
                .Multiple(true)
                .Async(async => async.Save("MyMethodName", "MyConrollerName")

In this case, how do I implement antiforgery? What changes I need to do in cshtml, controller?

Thanks, Adarsh

Was it helpful?

Solution

Hello if you use the Kendo Upload wrapper for MVC the antiforgery will be send automatically to the server.

Since you are using the old extensions you might need to use the OnUpload event to manually find that value and send it to the server.

e.g.

function onMyUpload(e){
    e.data = { "__RequestVerificationToken": $('input[name=__RequestVerificationToken]').val() };
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top