Jump to content

Search the Community

Showing results for tags '__RequestVerificationToken'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • W3Schools
    • General
    • Suggestions
    • Critiques
  • HTML Forums
    • HTML/XHTML
    • CSS
  • Browser Scripting
    • JavaScript
    • VBScript
  • Server Scripting
    • Web Servers
    • Version Control
    • SQL
    • ASP
    • PHP
    • .NET
    • ColdFusion
    • Java/JSP/J2EE
    • CGI
  • XML Forums
    • XML
    • XSLT/XSL-FO
    • Schema
    • Web Services
  • Multimedia
    • Multimedia
    • FLASH

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Languages

Found 1 result

  1. Would anyone guide something for the error below? "The required anti-forgery form field "__RequestVerificationToken" is not present." The error occurs when trying to delete a row in the table on the button below: <button onclick="return false;">Excluir</button> $("#add").click(function () { var token = $('[name=__RequestVerificationToken]').val(); $.ajax({ url: '@Url.Action("AddComponente", "Medicamento_formula")', cache: false, headers: { "__RequestVerificationToken": token }, type: "POST", data: $('#formcomp').serializeArray(), success: function (data) { if (data.success) { $('#tabelacomposicao > tbody:last').append('<tr>' + '<td hidden>' + data.id + '</td>' + '<td>' + data.descricao + '</td>' + '</td>' + '<td>' + data.excipiente + '</td>' + '<td>' + data.unidade_Medida + '</td>' + '<td>' + data.principio + '</td>' + '<td>' + data.quantidade + '</td>' + '<td>' + '<input type="image" src="/Images/excluir.png" onclick="clicado(this)">' + '</td>' + '</tr>'); $('#formcomp')[0].reset(); $("#validacaocomposicao").html(""); } else { $("#validacaocomposicao").html(data.msg); } } }); return false; }); function clicado(a) { var token = $('[name=__RequestVerificationToken]').val(); console.log($(a).closest('tr')[0].rowIndex); var linhaIndex = $(a).closest('tr')[0].rowIndex; var codigo = $(a).closest('tr').children('td')[0].innerText; $.ajax({ type: "POST", url: '@Url.Action("DelComponente", "Medicamento_formula")', cache: false, headers: { "__RequestVerificationToken": token }, contentType: 'application/json; charset=utf-8', data: { codigo: codigo }, success: function (data) { document.getElementById("tabelacomposicao").deleteRow(linhaIndex); console.log("ok"); } }); } CONTROLLER: [AttributeUsage(AttributeTargets.Class)] public class ValidateAntiForgeryTokenOnAllPosts : AuthorizeAttribute { public override void OnAuthorization(AuthorizationContext filterContext) { var request = filterContext.HttpContext.Request; // Only validate POSTs if (request.HttpMethod == WebRequestMethods.Http.Post) { // Ajax POSTs and normal form posts have to be treated differently when it comes // to validating the AntiForgeryToken if (request.IsAjaxRequest()) { var antiForgeryCookie = request.Cookies[AntiForgeryConfig.CookieName]; var cookieValue = antiForgeryCookie != null ? antiForgeryCookie.Value : null; AntiForgery.Validate(cookieValue, request.Headers["__RequestVerificationToken"]); } else { new ValidateAntiForgeryTokenAttribute() .OnAuthorization(filterContext); } } } }[HttpPost] [ValidateAntiForgeryToken] public ActionResult DelComponente(string codigo) { var _Codigo = Convert.ToInt32(codigo); Composicao.Remove(_Codigo); return Json(new { success = true }); } CREATE @using (Html.BeginForm("Create", "Medicamento_formula", FormMethod.Post, new { id = "formularioprincipal" })){ @Html.AntiForgeryToken() @Html.ValidationSummary(true)} <table class="table table-hover table-bordered" id="tabelacomposicao"> <thead> <tr style="font-size:10px"> <th> <i> NOME</i> </th> <th> <i> EXCIPIENTE</i> </th> <th> <i> UNIDADE DE MEDIDA</i> </th> <th> <i> PRINCIPIO ATIVO</i> </th> <th> <i> QUANTIDADE</i> </th> <th> <i>EXCLUIR</i> </th> </tr> </thead> <tbody id="linhascomp"> @foreach (var item in @ViewBag.ComposicaoFormula) { <tr style="font-size:10px"> <td> @item.descricao </td> <td> @item.excipiente </td> <td> @item.unidade_Medida </td> <td> @ViewBag.PrincipioAtivo.Find(item.cod_Principio_Ativo).descricao </td> <td> @item.quantidade </td> <td> <button onclick="return false;">Excluir</button> </td> </tr> } </tbody> </table>
×
×
  • Create New...