|
| 1 | +# MVC Integration with Blazor 9 |
| 2 | + |
| 3 | +This application now supports both ASP.NET Core MVC and Blazor components running side-by-side. |
| 4 | + |
| 5 | +## Architecture |
| 6 | + |
| 7 | +The application follows the integration pattern described in [Microsoft's Blazor Component Integration documentation](https://learn.microsoft.com/en-us/aspnet/core/blazor/components/integration?view=aspnetcore-9.0). |
| 8 | + |
| 9 | +### Key Components |
| 10 | + |
| 11 | +1. **Program.cs Configuration** |
| 12 | + - `AddControllersWithViews()` - Adds MVC services |
| 13 | + - `AddRazorPages()` - Adds Razor Pages support |
| 14 | + - `MapControllerRoute()` - Maps traditional MVC routes |
| 15 | + - `MapRazorPages()` - Maps Razor Pages routes |
| 16 | + - `MapRazorComponents<App>()` - Maps Blazor components |
| 17 | + |
| 18 | +2. **MVC Structure** |
| 19 | + - `Controllers/` - Contains MVC controllers (e.g., HomeController) |
| 20 | + - `Views/` - Contains Razor views (.cshtml files) |
| 21 | + - `Views/Shared/` - Shared layouts and partial views |
| 22 | + - `Views/_ViewImports.cshtml` - Global imports for views |
| 23 | + - `Views/_ViewStart.cshtml` - Default layout configuration |
| 24 | + |
| 25 | +## Routing |
| 26 | + |
| 27 | +- **MVC Routes**: `/Home/Index`, `/Home/About` (follows pattern: `/{controller}/{action}`) |
| 28 | +- **Blazor Routes**: `/` (root) and all other routes defined in Blazor components |
| 29 | + |
| 30 | +## Usage |
| 31 | + |
| 32 | +### Access MVC Views |
| 33 | +Navigate to: |
| 34 | +- http://localhost:5168/Home/Index - MVC home page |
| 35 | +- http://localhost:5168/Home/About - MVC about page |
| 36 | + |
| 37 | +### Access Blazor App |
| 38 | +Navigate to: |
| 39 | +- http://localhost:5168/ - Blazor application root |
| 40 | + |
| 41 | +## Benefits of This Integration |
| 42 | + |
| 43 | +1. **Gradual Migration**: Existing MVC applications can gradually adopt Blazor |
| 44 | +2. **Best of Both Worlds**: Use MVC for traditional request/response scenarios, Blazor for rich interactive experiences |
| 45 | +3. **Shared Infrastructure**: Both MVC and Blazor share the same middleware pipeline and services |
| 46 | +4. **SEO Friendly**: MVC views can provide server-rendered content for better SEO |
| 47 | + |
| 48 | +## Development |
| 49 | + |
| 50 | +The application uses .NET 9 and follows standard ASP.NET Core conventions: |
| 51 | +- Controllers inherit from `Controller` |
| 52 | +- Views use Razor syntax (.cshtml) |
| 53 | +- Blazor components use Razor component syntax (.razor) |
| 54 | + |
| 55 | +## Building and Running |
| 56 | + |
| 57 | +```bash |
| 58 | +# Build the solution |
| 59 | +dotnet build RFPAPP.sln |
| 60 | + |
| 61 | +# Run the application |
| 62 | +cd RFPResponsePOC/RFPResponsePOC |
| 63 | +dotnet run |
| 64 | +``` |
| 65 | + |
| 66 | +The application will start on http://localhost:5168 (or https://localhost:7150 for HTTPS). |
0 commit comments