3

I am serialising my form and post it via javascript function

<form id="myform">
@model MyTable
 <input type="hidden" name="Id" value="@Model.Id"/>
 <input type="text" name="Email" value="@Model.Email"/>
 <input type="button" value="Update" onclick="update()" />
</form>

and put my update function in js file

function update() {
    var data = serialize(document.getElementById('myForm'));
    var req = new XMLHttpRequest();

    req.open("Post", "update", true);
    req.send("myData=" + data);
}

I am using form-Serialize javascript library for it

I am receiving data on my update function and it is something like below

Id=101&Email=test%40gmail.com

but when I send it to my controller

 [HttpPost]
 public void update(string myData)
 {
    // update ...     
 }

the input data i.e. myData is null. how can I post my data to the controller ?

0 Answers0