Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

antiforgerytoken mvc with ajax



        function DeletePersonel(id) {

                var data = new FormData();
                data.append("__RequestVerificationToken", "@HtmlHelper.GetAntiForgeryToken()");

                $.ajax({
                    type: 'POST',
                    url: '/Personel/Delete/' + id,
                    data: data,
                    cache: false,
                    processData: false,
                    contentType: false,
                    success: function (result) {

                    }
                });

        }
    

        public static class HtmlHelper
        {
            public static string GetAntiForgeryToken()
            {
                System.Text.RegularExpressions.Match value = System.Text.RegularExpressions.Regex.Match(System.Web.Helpers.AntiForgery.GetHtml().ToString(), "(?:value=")(.*)(?:")");
                if (value.Success)
                {
                    return value.Groups[1].Value;
                }
                return "";
            }
        }
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #antiforgerytoken #mvc #ajax
ADD COMMENT
Topic
Name
1+3 =