问题描述
我有一个带有以下代码的控制器:
I have a controller with the codes like this:
[AcceptVerbs("POST")]
public ActionResult Create(FormCollection collection)
{
//why is that the collection is null?
}
我正在使用ajax.actionlink调用此操作.
I am calling this action using the ajax.actionlink.
我的问题是集合为null,这与我是否使用commit(input)按钮不同表单集合具有值.
my problem is the collection is null, unlike if i use the submit(input) buttonthe formcollection has values.
推荐答案
FormCollection 具有与之关联的默认活页夹,该活页夹始终会初始化集合,并且永远不要获取null
.与使用表单提交按钮相比,使用Ajax.ActionLink时您很可能有一个空集合.这是因为ActionLink方法在执行AJAX请求时不会发布任何表单值.
FormCollection has a default binder associated with it which always initializes the collection and you should never get null
. It is more likely that you have an empty collection when using Ajax.ActionLink in contrast to when using a form submit button. This is because the ActionLink method doesn't POST any form values when it performs the AJAX request.
这篇关于如何使用ajax.actionlink获取formcollection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!