There is a site (Razor), on the cshtml page:

<script type="text/javascript"> $(function () { $("#Search").click(function () { $.ajax({ type: "POST", url: "/Home/GetNodes/", data: JSON.stringify("100"), success: function (data) { alert(data); }, error: function (request, status, err) { alert(request + " " + status + " " + err); } }); }); </script> <input type="button" id="Search" title="Search" value="Search" /> 

App_Code / HomeController.cs controller:

 public class HomeController:Controller { public ActionResult Index() { return View(); } [HttpPost] public JsonResult GetNodes(string key) { return Json(true); } } 

Global.asax:

 <%@ Application Language="C#" %> <%@ Import Namespace="System.Web.Mvc" %> <%@ Import Namespace="System.Web.Routing" %> <script runat="server"> void Application_Start(object sender, EventArgs e) { GlobalFilters.Filters.Add(new HandleErrorAttribute()); AreaRegistration.RegisterAllAreas(); RouteTable.Routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); RouteTable.Routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional }); } </script> 

By pressing the button, the error part of the ajax request is always triggered. What needs to be added / corrected?

    1 answer 1

    Try this: data:JSON.stringify({key:"100"})