我有一个非常复杂的表单,我正在使用 MVC 模型绑定来捕获所有信息
我已经将它设置为捕获所有可能发生的不同提交,因为表单上有大约 10 个不同的提交按钮,还有 2 个图像按钮
我试图通过捕获图像按钮提交变得有点聪明(或者我认为),并创建了一个子类,以便我可以捕获返回的 x 值
public class ImageButtonViewData {
public int x { get; set; }
public string Value { get; set; }
}
父类看起来像这样
public class ViewDataObject {
public ImageButtonViewData ImageButton { get; set; }
public ViewDataObject(){
this.ImageButton = new ImageButton();
}
}
图像按钮的 html 然后看起来像
<input type="image" id="ViewDataObject_ImageButton" name="ViewDataObject.ImageButton" />
这适用于除 Chrome 之外的所有浏览器。
当我在 chrome 中调试它时,Request.Form 对象包含我期望的值,但是在模型绑定发生后,ViewDataObject 上的 ImageButton 属性已设置为 null
我可以看到提交值之间的唯一区别是 Chrome 将 x 传递为小写 (ViewDataObject.ImageButton.x) 而 IE 将其传递为大写 (ViewDataObject.ImageButton.X) 但我不认为模型绑定注意到属性名称上的大小写
有没有人有任何想法?
编辑 => 只是为了澄清,我不是想找到解决方法,我想弄清楚为什么这种技术在 Chrome 中不起作用,因为它适用于所有其他浏览器并且正在传递正确的数据通过