How can I implement a textbox that saves user input to a database using jQuery Ajax in an Asp.net MVC4 application? For example, if I type "my new task" in the textbox and click on a button, it should save this input in the database with the project ID and the UserID of the logged-in user. How can I achieve this in MVC4? Here is a snippet of my code:
public actionresult Insert(task, projectId, UserId)
{
//linq to sql goes here...
}
Here is the Ajax code:
source: function(request, response) {
$.ajax({
url: pagePath + "/insert",
data: "{ 'id': '" + request.term + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
dataFilter: function(data) { return data; },
success: function(data) {
response($.map(data.d, function(item) {
{
value = item.Name
return value;
}
}))
},
error: function(XMLHttpRequest, callStatus, errorThrown) {
alert(callStatus);
}
});
},
Could someone please review and offer guidance on whether this approach is correct?