我有一个表单在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.InspecoesController1[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
解决方法
这就是我们在我们的应用程序:
属性
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
