AntiForgeryToken With Jquery Ajax Calls Using ViewModels?

I have read through here about getting the AntiForgeryToken working with Jquery ajax reuests and I basically have to make sure I include the token with my post/ajax call using something like

data: { 

However... I am using ViewModels and creating my view model object, assigning my values and then JSON.stringify'ing it and passing it as the data (As per below)

        // Ajax call here
    // Make a view model instance
    var ajaxEditPermissionViewModel = new Object();
    ajaxEditPermissionViewModel.HasPermission = isChecked;
    ajaxEditPermissionViewModel.Permission = permission;
    ajaxEditPermissionViewModel.Category = category;
    ajaxEditPermissionViewModel.MembershipRole = role;

    // Ajax call to post the view model to the controller
    var strung = JSON.stringify(ajaxEditPermissionViewModel);

        url: '/Admin/Permissions/UpdatePermission',
        type: 'POST',
        dataType: 'json',
        data: strung,
        contentType: 'application/json; charset=utf-8',
        success: function (data) {
        error: function (xhr, ajaxOptions, thrownError) {
            ShowUserMessage("Error: " + xhr.status + " " + thrownError);

I'm a bit confused how I would pass the token in using my current setup?? Any advice greatly appreciated.


Is there a specific reason you feel the need to stringify your result? We just do this..

        type: "POST",
        data: {
            permission: Permission, 
            // other fields

See this article for how to pass your token using this way of passing parameters:

Need Your Help

AVAssetExportSession outputfile

iphone ios video compression avassetexportsession

How should the AVAssetExportSession output file look like? I'm trying to compress a video from an ALAsset item and it doesn't work. I'm guessing the output file has something to do with it.

I have a list with over a million objects in it, trying to find the fastest way to search through it

c# dictionary hash hashset ilist

I have a list that stores well over a million objects within it. I need to look through the list and update the objects found through the below query as efficiently as possible.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.