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

我有一个表单在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.ICollection
1[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

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....