加入收藏 | 设为首页 | 会员中心 | 我要投稿 十堰站长网 (https://www.0719zz.com/)- 混合云存储、网络、视频终端、云计算、媒体处理!
当前位置: 首页 > 编程开发 > asp.Net > 正文

ASP.Net MVC 4窗体与2提交按钮操作

发布时间:2023-02-17 10:56:04 所属栏目:asp.Net 来源:互联网
导读:我有一个表单在ASP.Net和剃刀。 我需要两种方式提交表单:一种是通过编辑操作,另一种是通过验证操作。 我应该怎么做呢? 我不介意使用JavaScript。 编辑: 使用自定义属性我得到这个错误。 The current request for action Resultados on controller type I
  我有一个表单在ASP.Net和剃刀。
  我需要两种方式提交表单:一种是通过编辑操作,另一种是通过验证操作。
 
  我应该怎么做呢?
 
  我不介意使用JavaScript。
 
  编辑:
 
  使用自定义属性我得到这个错误。
 
  The current request for action ‘Resultados’ on controller type ‘InspecoesController’ is ambiguous between the following action methods:
  System.Web.Mvc.ActionResult Validar(System.Collections.Generic.ICollection1[Waveform.IEP.Intus.Server.Web.viewmodels.Resultadoviewmodel]) on type Waveform.IEP.Intus.Server.Web.Controllers.InspecoesController
  System.Web.Mvc.ActionResult Resultados(System.Collections.Generic.ICollection1[Waveform.IEP.Intus.Server.Web.viewmodels.Resultadoviewmodel]) on type Waveform.IEP.Intus.Server.Web.Controllers.InspecoesController
 
  解决方法
  这就是我们在我们的应用程序:
  属性
  public class HttpParamActionAttribute : ActionNameSelectorAttribute
  {
      public override bool IsValidName(ControllerContext controllerContext,string actionName,MethodInfo methodInfo)
      {
          if (actionName.Equals(methodInfo.Name,StringComparison.InvariantCultureIgnoreCase))
              return true;
  
          var request = controllerContext.RequestContext.HttpContext.Request;
          return request[methodInfo.Name] != null;
      }
  }
  用它装饰的动作:
 
  [HttpParamAction]
  public ActionResult Save(MyModel model)
  {
      // ...
  }
  
  [HttpParamAction]
  public ActionResult Publish(MyModel model)
  {
      // ...
  }
  HTML /剃刀
 
  @using (@Html.BeginForm())
  {
      <!-- form content here -->
      <input type="submit" name="Save" value="Save" />
      <input type="submit" name="Publish" value="Publish" />
  }
  提交按钮的名称属性应该匹配操作/方法名称
 
  这样你不必在JavaScript中硬编码url

(编辑:十堰站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读