I am tring to pass data using ajax and trigger conteroller in my mvc project
this is my controller
public class FileController : Controller
{
[HttpPost]
public ActionResult Index(string data)
{
return View();
}
}
this is the js
$('#getmessage').on('click', function () {
var text = '';
$('#discussion>li').each(function () {
text += $(this).text();
text += '\n'
})
console.log(text)
$.ajax({
url: 'http://localhost:22828/File/Index',
type: 'POST',
data: text,
success: function (result) {
console.log("data sended");
}
})
})
I need to pass the text to the controller, but in my controller I get NULL
Can someone please put some light on this?
Thanks in advance