我特林使用AJAX和触发conteroller数据掠过我的MVC项目JQuery/MVC/ajax如何使用ajax发布数据到控制器?
这是我的控制器
public class FileController : Controller
{
[HttpPost]
public ActionResult Index(string data)
{
return View();
}
}
这是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");
}
})
})
我需要通过文本控制器,但在我的控制器中,我得到了NULL
有人可以请说明一点吗?
在此先感谢
控制器仍然获得数据= null – barak
当你做'console.log(文本)',有什么吗?另外请记住用';'关闭你的线条,这样可以让每个人都更容易知道线路的起点和终点。 – Morgs
是在我的console.log我得到的文字 – barak