Seems a simple thing but I've spent all day looking through posts all over the web with little recourse! Please help. I have a simple request to be posted to a MVC controller...
$(document).ready(function () {
$('#json_request').on("click", function () {
// send request to server for menu json data
$.ajax({
type: "POST",
url: location.protocol + "//" + location.host + "/Tablet/Menu",
data: { restaurantId: $('#restaurantId option:selected').val(), mealSessionId: $('#mealSessionId option:selected').val() },
success: function (menuData) {alert(menuData); },
error: function () { alert("failed"); }
});
});
});
The request just won't reach the controller! The app works fine when I post the request as a Html form. It works fine with the Visual Studio Development Server too. I get 404 error with IIS 7.0 / ASP.NET / MVC 4. Possibly, contentType: application/x-www-form-urlencoded does not get through the http-protocol filters. Do I have to set those specifically? How? Thanks for your help. I am not send the request as a json, so i did not try contentType: application/json.
Controller / Action:
[HttpPost]
public ActionResult Menu(short restaurantId, short mealSessionId)
{
try
{
MenuInput menuInput = new MenuInput(restaurantId, mealSessionId);
menuInput.LoadMenu();
if (Request.IsAjaxRequest())
{
MemoryStream ms = new MemoryStream();
menuInput.AsJson(ms);
string jsonString = Encoding.UTF8.GetString(ms.ToArray());
JsonResult result = Json(jsonString, "text/x-json");
ms.Close();
return result;
}
else
{
return View("MenuInformation", menuInput);
}
}
catch (Exception ex)
{
System.Console.Write(ex.ToString());
return View();
}
}