0

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.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
h3n
  • 5,142
  • 9
  • 46
  • 76

2 Answers2

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.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
0

You need to use Ajax.BeginForm

Muthu Kumaran
  • 17,682
  • 5
  • 47
  • 70
Peter Marshall
  • 1,231
  • 1
  • 13
  • 22