The following Ajax code doesn't even trigger my action if the input variable (a) isn't set to Null.
Ajax code:
var ab = "Chocolate Smoothies ya know?";
$("#customerSubmit").submit(function (e) {
e.preventDefault();
$.ajax({
url: "/api/Booking/lander",
method: "post",
data: { a: ab }
})
});
The following my controller code:
[HttpPost]
public void lander(string a)
{
System.Diagnostics.Debug.WriteLine(a);
}
And when I do not set it to null, the input received is null.
screenshot when the breakpoint is triggered:
I've used type/method/etc.. Nothing seems to work
Update:
I even tried the following but no use:
Update 2:
Even the following didn't work and one of the following also gave me -> "Failed to load resource: the server responded with a status of 405 (Method Not Allowed)"
var ab = 'Chocolate Smoothies ya Know?';
$.ajax({
url:"/api/Booking/lander",
data: {'': ab}
});
With
public string lander([FromUri]string asx) ////and asx = "" and /// asx = null
Update 3
Something extremely weird happened, I used the following code:
and I got the following error:
and when I used
////(string a = "")
it triggered my action for some unknown reason and the following happened.
The following is my WebApiConfig code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
namespace HotelManagementSystem
{
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
//routes.MapHttpRoute("RestApiRoute", "Api/{controller}/{id}", new { id = RouteParameter.Optional }, new { id = @"\d+" }); //this replaces your current api route
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
}
Update 4:
Even the following set up did not work: