Need help with MVC route when jQuery AJAX is called by route

I am trying to access a simple ASP.NET MVC path, but with an error:

The parameter dictionary contains null for the parameter 'isFoo' of type with a null value of 'System.Boolean' for the method 'System.Web.Mvc.ActionResult Transform (Boolean, System.String)' in .. blah blah blah.

Those. the boolean property does not receive set ... which means that the value does not receive.

So, I have an Action method called Transform (..), and it does not take values ​​that are HTTP messages with jQuery. This is how my published values ​​are lost :(

The MVC site is a standard ASP.NET MVC File-> New-> MVC Web Application file. Nothing has changed except the addition of a new controller class. what he.

using System.Web.Mvc;
using System.Web.Mvc.Ajax;

namespace WorldDomination.EbonHawk.Web.Controllers
{
    public class AjaxController : Controller
    {
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Transform(bool isFoo, string bar)
        {
            // blah....
            return View();
        }

    }
}

, jQuery....

$.ajax({
    type: "POST",
    url: "/ajax/transform",
    data: "isfoo=true&bar=" + $("#Bar").val(),
    contentType: "application/json;",
    dataType: "json",
    success: function() { alert("it worked"); },
    failure: function() { alert("Uh oh"); }
});

FireBug, , POST url. - ?

+3
3

, jQuery...

, - JSON, . dataType AJAX, jQuery .

+3

. , dataType, data :

...
data: { isfoo: true, bar: $("#Bar").val() },
...
+1

ASP.NET MVC POST GET . HTTP-, . , , jQuery .

$.ajax

$.ajax({
    type: "POST",
    url: "<%= Url.Action("Transform", "Ajax") %>",
    data: { isfoo: true, bar: $("#Bar").val() },
    contentType: "application/json;",
    dataType: "json",
    success: function() { alert("it worked"); },
    failure: function() { alert("Uh oh"); }
});

, . , URL- , POST. , , . , , URL .

EDIT:

GET, , isfoo = read isFoo =, . , cap .

0

Source: https://habr.com/ru/post/1708130/


All Articles