我有一张ASP的表格.网和剃刀.
我需要有两种提交表单的方式:一种是通过Edit
操作,另一种是通过Validate
操作.
我该怎么做呢?
我不介意为此使用JavaScript.
编辑:
使用自定义属性,我得到了这个错误.
当前对控制器类型"InspecoesController"的操作"Resultados"的请求在以下操作方法之间不明确:
我有一张ASP的表格.网和剃刀.
我需要有两种提交表单的方式:一种是通过Edit
操作,另一种是通过Validate
操作.
我该怎么做呢?
我不介意为此使用JavaScript.
编辑:
使用自定义属性,我得到了这个错误.
当前对控制器类型"InspecoesController"的操作"Resultados"的请求在以下操作方法之间不明确:
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
提交按钮的属性应与操作/方法名称匹配
这样,您就不必在javascript中对URL进行硬编码