Dhaval Javiya
Dhaval Javiya

Reputation: 154

How to passing Controller a FormCollection and a class type object to action

i am facing problem to Passing Controller a Form Collection and a class type object to action using ajax call.

below are the my code.

    [HttpPost]
    public ActionResult AddDealNotes(DealNote objDealNote,FormCollection fc)
      {

             //code
      }

Upvotes: 0

Views: 1408

Answers (1)

Robbie Tapping
Robbie Tapping

Reputation: 2556

To send a javascript ajax request using the jquery $.post object you need to make sure you use the dataType & contentType parameters.

<script>
function sendDealNotes(note, form)
{


var dataOutput = {"note": note,"form": form.serializeArray()};

var sendData = JSON.stringify(dataOutput );

var jqxhr = $.ajax({url:"/Controller/AddDealNotes", type:"POST", dataType:"json", contentType:"application/json",data:sendData})
  .done(function() {
    alert( "success" );
  })
  .fail(function(err) {
    alert( "error" + err );
  })
  .always(function() {
    alert( "complete" );
  });


}
</script>

Upvotes: 1

Related Questions