0

I am serializing my form to be sent back to the server where it auto binds to a view model. However want to send 2 more parameters to the server but not sure how

public ActionResult Test(MyViewModel vm, DateTime date, bool isSomething)

I am not sure how my "data" parameter in my ajax call should look like

   data: { 'vm':  frm, 'date': date, 'isSomething': true }, // this does not work.

Normally I would have just done this

   data: frm,

My code complies and no javascript errors however it appends 'vm' to all of the frm ones and then on the server it does not know how to bind it. Basically the json key is messing up the binding.

When I do

data: frm  // result of items look like this Id 7b97dcc7-3f8d-4cc0-ad2a-a104010f683d

when I do

data: {'vm' : frm} // result looks like this vm[0][name]    Id

some how I have to send it so it does need a key.

chobo2
  • 83,322
  • 195
  • 530
  • 832

1 Answers1

0

There is a syntax error in your action method

public ActionResult Test(MyViewModel, vm, DateTime date, bool isSomething)

should be

public ActionResult Test(MyViewModel vm, DateTime date, bool isSomething)

You may also want to add this to your jquery ajax call

data: { 'vm':  frm, 'date': date, 'isSomething': true },
traditional: true

It will allow for you to "use the traditional style of param serialization."

Travis J
  • 81,153
  • 41
  • 202
  • 273