In an asp.net mvc application I have a method that returns a JsonResult to the view. It works perfectly on my local machine, however when the application is deployed on the web hosting server, when I try get this data by hitting the view’s link I get a 404 Not Found in Firebug. Is there anyone who know a possible reason why this could be happening? My code snippets of how I generate the path are below:
private void get_info()
{
var serviceUri = new Uri("/getcountrydata/" + country_name + "/" + arms[0].Name + "/" + arms[1].Name + "/" + arms[2].Name + "/" + arms[3].Name, UriKind.Relative);
var webClient = new WebClient();
webClient.OpenReadCompleted += openReadCompleted;
webClient.OpenReadAsync(serviceUri);
}
Global.asax routing below:
routes.MapRoute(
"getcountrydata",
"getcountrydata/{country}/{indicator1}/{indicator2}/{indicator3}/{indicator4}",
new { controller = "Home", action = "getcountrydata" }
);
The getcountrydata method is as follows:
public JsonResult getcountrydata(string country, string indicator1, string indicator2, string indicator3, string indicator4)
{
LegoData legoData = captainClimateRepostory.GetLegoData(country, indicator1, indicator2, indicator3, indicator4);
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(LegoData));
MemoryStream ms = new MemoryStream();
ser.WriteObject(ms, legoData);
return Json(ms.ToArray(), JsonRequestBehavior.AllowGet);
}
I think it is a problem with the url you are providing for the action. It is not relative in respect to the host server. Check this SO post..
jquery ajax call to JsonResult controller method results in 404 on IIS6