问题
I have a controller with the codes like this:
[AcceptVerbs("POST")]
public ActionResult Create(FormCollection collection)
{
//why is that the collection is null?
}
I am calling this action using the ajax.actionlink.
my problem is the collection is null, unlike if i use the submit(input) button the formcollection has values.
回答1:
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.
回答2:
You need to use Ajax.BeginForm
来源:https://stackoverflow.com/questions/1550219/how-to-get-formcollection-using-ajax-actionlink