I am trying to use jQuery ajax to save the value that the user entered in the Textbox to the database. But I am struck how to proceed. What I did so far:
User clicks button and I call jQuery function and am calling the controller
comments = $("#txtComments").val();
var request = $.ajax({
url: "/Home/SaveCommentsData",
type: "POST",
data: { comment: comments },
dataType: "json"
});
and I am not sure how to get this comment value in the controller and send a value back to jQuery on success.
try data like this
data :{'comment':comments}
and use the same variable as string type in controller action
comments = $("#txtComments").val();
var request = $.ajax({
url: "/Home/SaveCommentsData",
type: "POST",
data: { 'comment': comments },
dataType: "json"
});
Controller
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult SaveCommentsData( string comment)
{
//
}
Regards
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With