文章内容
2017/3/4 9:15:51,作 者: 黄兵
所需的防伪表单字段“__RequestVerificationToken”不存在
最近在写代码的时候提示:所需的防伪表单字段“__RequestVerificationToken”不存在。
解决方法如下:
@using(Html.BeginForm("AddArticle","Manage", FormMethod.Post,new{ enctype ="multipart/form-data"})){@Html.AntiForgeryToken()<divclass="ibox-content"><divclass="form-group">@Html.LabelFor(model => model.Title, htmlAttributes:new{ @class="control-label col-md-2"})<divclass="col-sm-10">@Html.TextBoxFor(model => model.Title,new{ @class="form-control", required ="", maxlength ="200"})@Html.ValidationMessageFor(model => model.Title,"",new{ @class="text-danger"})</div></div>@*<divclass="hr-line-dashed"></div><divclass="form-group">@Html.LabelFor(model => model.AuthorId, htmlAttributes:new{ @class="control-label col-md-2"})<divclass="col-sm-10">@Html.DropDownList("AuthorId", ViewData["authories"]asSelectList, htmlAttributes:new{ @class="form-control"})@Html.ValidationMessageFor(model => model.AuthorId,"",new{ @class="text-danger"})</div></div>*@<divclass="hr-line-dashed"></div><divclass="form-group">@Html.LabelFor(model => model.Keyword, htmlAttributes:new{ @class="control-label col-md-2"})<divclass="col-sm-10">@Html.TextBoxFor(model => model.Keyword,new{ @class="form-control", maxlength ="100"})@Html.ValidationMessageFor(model => model.Keyword,"",new{ @class="text-danger"})</div></div><divclass="hr-line-dashed"></div><divclass="form-group">@Html.LabelFor(model => model.Description, htmlAttributes:new{ @class="control-label col-md-2"})<divclass="col-sm-10">@Html.TextBoxFor(model => model.Description,new{ @class="form-control", maxlength ="200"})@Html.ValidationMessageFor(model => model.Description,"",new{ @class="text-danger"})</div></div><divclass="hr-line-dashed"></div><divclass="form-group">@Html.LabelFor(model => model.Body, htmlAttributes:new{ @class="control-label col-md-2"})<divclass="col-sm-10"><divclass="ibox float-e-margins"><divclass="ibox-title"><h5>文章内容</h5><divclass="ibox-tools"><aclass="collapse-link"><iclass="fa fa-chevron-up"></i></a><aclass="dropdown-toggle"data-toggle="dropdown"href="form_editors.html#"><iclass="fa fa-wrench"></i></a><ulclass="dropdown-menu dropdown-user"><li><a href="form_editors.html#">选项1</a></li><li><a href="form_editors.html#">选项2</a></li></ul><aclass="close-link"><iclass="fa fa-times"></i></a></div></div><divclass="ibox-content no-padding">@Html.TextAreaFor(model => model.Body,new{ @class="form-control note-codable summernote"})@Html.ValidationMessageFor(model => model.Body,"",new{ @class="text-danger"})</div></div></div></div><divclass="hr-line-dashed"></div><divclass="form-group"><divclass="col-sm-4 col-sm-offset-2"><buttonclass="btn btn-primary"type="submit">保存内容</button></div></div></div>}
增加一个:@Html.AntiForgeryToken()
// POST: /Manage/RemoveLogin[HttpPost][ValidateAntiForgeryToken]publicasync Task<ActionResult> RemoveLogin(stringloginProvider,stringproviderKey){ManageMessageId? message;var result = await UserManager.RemoveLoginAsync(User.Identity.GetUserId(),newUserLoginInfo(loginProvider, providerKey));if(result.Succeeded){var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());if(user !=null){await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);}message = ManageMessageId.RemoveLoginSuccess;}else{message = ManageMessageId.Error;}returnRedirectToAction("ManageLogins",new{ Message = message });}
评论列表