I am working on a project which should connect the Yahoo Weather API with ASP.Net MVC 3
After I have created the variables it has given me the error called “The type or namespace name ‘WeatherForecast’ could not be found (are you missing a using directive or an assembly reference?) C:\Users\kumi.SH\Documents\Learn\ASP.Net_MVC3\WeatherApp\WeatherApp\Controllers\HomeController.cs”
I have the following code in my HomeController.cs file:
public ActionResult GetWeather(string Id)
{
StringBuilder sb = new StringBuilder();
WeatherForecast wf = new WeatherForecast();
WeatherForecasts wfs = wf.GetWeatherByPlaceName(Id);
WeatherData[] wd = wfs.Details;
sb.AppendFormat("<B>Weather Forecast for {0}</B><br /><br />", wfs.PlaceName);
foreach (WeatherData d in wd)
{
if (!string.IsNullOrEmpty(d.WeatherImage))
{
sb.AppendFormat("<img src=\"{0}\" >", d.WeatherImage);
sb.AppendFormat(" {0}", d.Day);
sb.AppendFormat(", High {0}F", d.MaxTemperatureF);
sb.AppendFormat(", Low {0}F<br />", d.MinTemperatureF);
}
}
Response.Write(sb.ToString());
return null;
}
Can you please specify the namespaces which needs to use?
Thankx in advance……
It looks like your application uses the following web service?
http://www.webservicex.net/weatherforecast.asmx
If so, you will need to add a Service Reference to this service within the same project that you are trying to use it. I.e. the same project where the code in your example lives. Judging from the path in your example, that project is called “WeatherApp”.
You can do this by right clicking on the project node in Solution Explorer and selecting “Add Service Reference”. Then in the dialog that appears paste the service url (above) into the address bar and hit “Go” – Give it a name and then click “Ok”