正如卢克已经告诉.. Form Collection 是字典对象,仅包含名称,值对.. 为了将那个东西放入控制器,您需要通过 ajax 传递该自定义属性。
var form = $("#formid").serialize(),
custom = $("input:text").attr("customAttr1").val();
$.ajax({
type: "POST",
url: "/controller/ProcessData",
data:{collection :form,customAttr: custom },
dataType: "html",
traditional: true
});
在控制器中,您需要具有以下语法:
public ActionResult ProcessData(FormCollection collection ,string customAttr)
{
如果您需要传递多个自定义值,则需要从 ajax 请求中发布字符串数组并制作控制器签名,例如:
public ActionResult ProcessData(FormCollection collection ,string[] customArray)
{