Why TestData does not receive anything?
POST http://localhost:46628/Home/TestData 500 (Internal Server Error)
index.cshtml:
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<script src="~/Scripts/knockout-2.2.0.js"></script>
<button data-bind="click: sendata">send data</button>
<script>
function MyViewModel() {
var self = this;
self.sendata = function () {
$.ajax({
type: 'POST',
url: 'Home/TestData',
contentType: 'application/json; charset=utf-8',
data: { json: 'json', date: 'date' },
dataType: 'json'
});
}
}
ko.applyBindings(new MyViewModel());
</script>
Controller:
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
return View();
}
[HttpPost]
public void TestData(string json,string date)
{
Console.WriteLine(json);
}
}