Project Requirements:
- Backend: ASP.NET core MVC
- Frontend: HTML, CSS, JavaScript, Bootstrap for styling.
- API Integration: Use a third-party weather API to fetch real-time weather data (e.g., OpenWeatherMap, WeatherAPI).
Create a New ASP.NET Core MVC Project:
- Open Visual Studio.
- Select "Create a new project."
- Choose "ASP.NET Core Web Application" and choose "ASP.NET Core Web App (Model-View-Controller" template and click "Next."
- Name your project "Your Desired Name".
- Chose the location you want to save the project and click "Next"
- Framework ".NET8.0(Long Term Support) and leave the rest to default and "Create"
Set Up API Integration Register for a Weather API Key:
- Go to a weather API provider like OpenWeatherMap or WeatherAPI.
- Sign up and obtain an API key.
Create a Service for Weather API Integration:
- In Visual Studio, create a new folder named Services.
- Add a new class named WeatherService.cs
- Make sure to replace "YOUR_API_KEY" with your actual API key.
Create the Weather Data Model
- In the Models folder add a new class named 'WeatherData.cs'
Install Newtonsoft.Json Package: Install the Newtonsoft.Json package via NuGet Package Manager to handle JSON deserialization
Create the Weather Controller or you can use the HomeController
Register the Service in Program.cs: Add the following to the ConfigureServices method:
- builder.Services.AddHttpClient();
Edit the index.cshtml page in the Views folder
Create the Partial View: In the shared folder, create a _WeatherPartial.cshtml: