ASP.Net MVC 4与表2的提交按钮/动作 [英] ASP.Net MVC 4 Form with 2 submit buttons/actions

查看:131
本文介绍了ASP.Net MVC 4与表2的提交按钮/动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASP.Net和剃须刀的形式。

我需要提交两种方式表示形式。上穿过修改操作,另一个通过验证行动去。

我应该如何去这样做呢?

我不介意使用JavaScript这一点。

编辑:

使用自定义属性我得到这个错误。


  

采取行动的当前请求Resultados控制器类型InspecoesController'是下面的操作方法之间暧昧:
      System.Web.Mvc.ActionResult Validar(System.Collections.Generic.ICollection<$c$c>1[Waveform.IEP.Intus.Server.Web.ViewModels.ResultadoViewModel])上式Waveform.IEP.Intus.Server.Web.Controllers.InspecoesController
      System.Web.Mvc.ActionResult Resultados(System.Collections.Generic.ICollection1[Waveform.IEP.Intus.Server.Web.ViewModels.ResultadoViewModel])在类型Waveform.IEP.Intus.Server.Web.Controllers.InspecoesController



解决方案

这就是我们在我们的应用程序:结果
属性

 公共类HttpParamActionAttribute:ActionNameSelectorAttribute
{
    公众覆盖布尔IsValidName(ControllerContext controllerContext,串actionName,MethodInfo的MethodInfo的)
    {
        如果(actionName.Equals(methodInfo.Name,StringComparison.InvariantCultureIgnoreCase))
            返回true;        VAR请求= controllerContext.RequestContext.HttpContext.Request;
        返回请求[methodInfo.Name]!= NULL;
    }
}

动作饰吧:

 
[HttpParamAction]
公众的ActionResult保存(为MyModel模型)
{
    // ...
}[HttpParamAction]
公众的ActionResult发布(为MyModel模型)
{
    // ...
}

HTML /剃须刀

  @using(@ Html.BeginForm())
{
    &LT;! - 形式的内容在这里 - &GT;
    &LT;输入类型=提交名称=保存值=保存/&GT;
    &LT;输入类型=提交名称=发布值=发布/&GT;
}

名称提交按钮应符合动作/方法的名称属性。

这样,您就不必硬在JavaScript code网址

I have a form in ASP.Net and razor.

I need to have two ways of submitting said form. On that goes through the Edit action and another that goes through the Validate action.

How should I go about doing this?

I don't mind using JavaScript for this.

EDIT:

Using the custom attribute I get this error.

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

解决方案

That's what we have in our applications:
Attribute

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;
    }
}

Actions decorated with it:


[HttpParamAction]
public ActionResult Save(MyModel model)
{
    // ...
}

[HttpParamAction]
public ActionResult Publish(MyModel model)
{
    // ...
}

HTML/Razor

@using (@Html.BeginForm())
{
    <!-- form content here -->
    <input type="submit" name="Save" value="Save" />
    <input type="submit" name="Publish" value="Publish" />
}

name attribute of submit button should match action/method name

This way you do not have to hard-code urls in javascript

这篇关于ASP.Net MVC 4与表2的提交按钮/动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆