Reputation: 2319
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);
}
Upvotes: 1
Views: 3701
Reputation: 22770
Tanveer-Ibn- Haresh is correct -you are providing a URL assumes app is running at the root. My tutorial [Working with the DropDownList Box and jQuery][1] [1]: http://www.asp.net/mvc/tutorials/javascript/working-with-the-dropdownlist-box-and-jquery/using-the-dropdownlist-helper-with-aspnet-mvc shows how to do this correctly.
Upvotes: 0
Reputation: 9098
Inside Silverlight you can build a URL relative to the page hosting your XAP:
Uri uri = new Uri(HtmlPage.Document.DocumentUri, "../getcountrydata/");
Even better - relative to your XAP:
Uri uri = new Uri(App.Current.Host.Source.AbsoluteUri, "../getcountrydata/");
Some more info here: http://weblogs.asp.net/lduveau/archive/2009/03/13/get-silverlight-xap-and-hosting-page-url.aspx
Upvotes: 1
Reputation: 300
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
Upvotes: 3