Google chrome 图像提交按钮与Chrome兼容,但dosn';你不能使用firefox吗?

Google chrome 图像提交按钮与Chrome兼容,但dosn';你不能使用firefox吗?,google-chrome,firefox,post,asp.net-mvc-4,custom-attributes,Google Chrome,Firefox,Post,Asp.net Mvc 4,Custom Attributes,我有以下HTML: 在我的控制器中,我有以下自定义属性 [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)] public class MultiButtonAttribute : ActionNameSelectorAttribute { public string MatchFormKey { get; set; } public string MatchForm

我有以下HTML:

在我的控制器中,我有以下自定义属性

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class MultiButtonAttribute : ActionNameSelectorAttribute
{
    public string MatchFormKey { get; set; }
    public string MatchFormValue { get; set; }
    public override bool IsValidName(ControllerContext controllerContext, string actionName, MethodInfo methodInfo)
    {
        return controllerContext.HttpContext.Request[MatchFormKey] != null &&
            controllerContext.HttpContext.Request[MatchFormKey] == MatchFormValue;
    }
}
单击delete时应调用以下操作方法

    [HttpPost]
    [MultiButton(MatchFormKey = "action", MatchFormValue = "Delete")]
    public ActionResult Delete(MessageModel model)
    {
        return Content("Delete clicked");
    }
这在Chrome上非常有效,但在Firefox中单击submit按钮时,不会调用我的操作方法Delete()


知道我做错了什么吗?

一些浏览器以不同的方式发送值。因此,您不必使用普通请求,而必须深入RoutedData,在那里可以找到所有值,包括来自Firefox的值。这是一个定制属性的修改版本,可与Chrome、Firefox和IE一起使用

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class MultiButtonAttribute : ActionNameSelectorAttribute
{
    public string MatchFormKey { get; set; }  
    public string MatchFormValue { get; set; } 
    public override bool IsValidName(ControllerContext controllerContext, string actionName, MethodInfo methodInfo)
    {
        if (controllerContext.HttpContext.Request.RequestContext.RouteData.Values[MatchFormKey] != null)
        {
            return (string)controllerContext.HttpContext.Request.RequestContext.RouteData.Values[MatchFormKey] == MatchFormValue;
        }
        return false;
    }
}
根据HTML规范,
单击时,发送名为
action.x
action.y
的表单参数,但不发送名为
action
的表单参数。Firefox遵循该规范,而Chrome则没有

不过,您的服务器端代码似乎明确地检查了
操作
,这就是它在Firefox中不起作用的原因