*
I have this error with my action. Error My Controller
[Authorize(Roles = ApplicationRoles.PAINELCHAMADA_EDITAR)] public ViewResultBase Editar(int IdEmpresa, int id) { var model = this.Service.Get(IdEmpresa, id); return base.PartialView(model); } [HttpPost] [Authorize(Roles = ApplicationRoles.PAINELCHAMADA_EDITAR)] public ActionResult Editar(PainelChamada item) { if (this.ModelState.IsValid) { try { this.Service.Update(item, this.GetFieldsToUpdate()); return RedirectToAction("Index"); } catch (ValidationException exception) { base.AddValidationErrors(exception); return base.View(item); } } else { return base.View(item); } }
View @model PainelChamada @{ this.ViewBag.Title = PainelChamadaResource.Titulo; this.ViewBag.SubTitle = Geral.Editar;
} @using (Html.BeginForm( this.DefaultActionEdit, "PainelChamada", "POST")) //new AjaxOptions //{ // InsertionMode = InsertionMode.Replace, // HttpMethod = "POST", // UpdateTargetId = "content" //})) { @Html.ValidationSummary() @Html.HiddenFor(i => i.Id)<input type="submit" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" value="Alterar" /> } what might be happening? I try create routes in GlobalAsax, but no have success.
*
最佳答案
这意味着有人向 Editar
操作发送请求并且没有为 IdEmpresa
参数指定值。
如果你想避免这个异常,你可以在路由映射中将 IdEmpresa
和 id
参数标记为可选,并在你的方法中使它们可以为空:
public ViewResultBase Editar(int? IdEmpresa, int? id)
但在这种情况下,您必须在操作中使这些值无效。
这种行为在网络爬虫中很常见。有一次,我遇到了同样的问题,所以我记录了所有发出这些请求的 IP——所有这些都是由谷歌网络爬虫完成的。所以就我而言,我只是忽略了那些异常(exception)
关于c# - 错误操作编辑 Controller MVC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27506098/