This question already has an answer here:
I'm working on C# UWP wheather application. I have a problem with ASP.NET web service, when I try to run the service on the browser, I see this error
System.NullReferenceException: Object reference not set to an instance of an object.
Source File: C:\Users\Kaceper\Documents\Visual Studio 2017\Projects\UWPWeatherService\UWPWeatherService\Controllers\HomeController.cs Wiersz: 17
Line 15: {
Line 16: // Validation / trimming
Line 17: var latitude = double.Parse(lat.Substring(0, 5));
Line 18: var longitude = double.Parse(lon.Substring(0, 5));
Line 19:
Here is my code:
HomeController.cs
public class HomeController : Controller
{
public async Task Index(string lat, string lon)
{
var latitude = double.Parse(lat.Substring(0, 5));
var longitude = double.Parse(lon.Substring(0, 5));
var weather = await Models.OpenWeatherMapProxy.GetWeather(latitude, longitude);
ViewBag.Name = weather.name;
ViewBag.Temp = ((int)weather.main.temp).ToString();
ViewBag.Description = weather.weather[0].description;
return View();
}
}
and the URL, which I'm passing in browser:
How can I fix this? please help
Aucun commentaire:
Enregistrer un commentaire