Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

[ValidateAntiForgeryToken] breaks page

$
0
0

I have an ASP .Net Core 1.1 MVC web app. When I add the [ValidateAntiForgeryToken] decoration to my Edit/Delete/Create controllers, the pages don't load (
HTTP 400 error). Any ideas why? I read somewhere that I have to add a corresponding @HtmlHelper.AntiForgeryToken to my Views, or something like that? But not sure where to put it... However, I've also read that it's not necessary to do this anymoer in ASP .Net Core...

Here is an example of my Edit view for a "Users" controller:

@model InspectionsData.Models.User

@{
    ViewData["Title"] = "Edit";
}<h2>Edit</h2><form asp-action="Edit"><div class="form-horizontal"><h4>User</h4><hr /><div asp-validation-summary="ModelOnly" class="text-danger"></div><div class="form-group" hidden><label asp-for="UserId" class="col-md-2 control-label"></label><div class="col-md-10"><input asp-for="UserId" class="form-control" /><span asp-validation-for="UserId" class="text-danger"></span></div></div><div class="form-group"><label asp-for="FirstName" class="col-md-2 control-label"></label><div class="col-md-10"><input asp-for="FirstName" class="form-control" /><span asp-validation-for="FirstName" class="text-danger"></span></div></div><div class="form-group"><label asp-for="LastName" class="col-md-2 control-label"></label><div class="col-md-10"><input asp-for="LastName" class="form-control" /><span asp-validation-for="LastName" class="text-danger"></span></div></div></div></form><div><a asp-action="Index">Back to List</a></div>

Thank you


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>