Search code examples
kendo-uitelerikkendo-asp.net-mvckendo-ui-mvckendo-window

Kendowwindow __RequestVerificationToken


I am opening an kendo window using the below jquery function.

I need to pass __RequestVerificationToken to the MVC Controller because I am having ValidateAntiForgeryToken Attribute.

However, I am not able to pass it. Can you please suggest how to pass __RequestVerificationToken while opening an kendoWindow

function OpenTest() {           

   var url =      '@Url.ActionWithArea("OpenTest", "Test", GlobalConst.AREA_Test)';

   url += "?test=" +$("#test").val() +
   "&test1=" +$("#test1").val();


windowElement = $('<div id = "abc" />').kendoWindow({
title: 'test',
content: url,
modal: true,
resizable: false,
draggable: false, 
width: 900,
height: 400,
close: function () {              windowElement.destroy(); }).data("kendoWindow").center().open();

  return false;
}

Solution

  • You might want to think about including this token at a more global scope in your application so you don't have to meddle with it on a per call basis.

    There is an example over on the Kendo UI forums, about halfway down. The data signature of your route should look like:

    transport: {
        read: {
            url: url,
            type: "POST",
            data: {__RequestVerificationToken: $("input[name=__RequestVerificationToken]").val()
            }
        }
    

    Or in your case, something like this -->

    '@Url.ActionWithArea("OpenTest", "Test", new { __RequestVerificationToken=<value> }),GlobalConst.AREA_Test)';