I am using Visual Studio 2019 Community16.3.0 Preview 4.0, .NET Core 3.0 RC1, ASP.NET Core 3, Entity Framework 3 RC1
I am reading ASP.NET Core document. I know ASP.NET Core has 4 programming models:
First question: I wonder, Can I have 2 different ASP.NET Core programming models in same web-app?
Second question: I create an Blazor web app follow this tutorial: https://docs.devexpress.com/Blazor/401057/getting-started/create-a-new-application , it run success.
Blazor
@page "/weather"
<h1>Weather</h1>
<DxTextBox></DxTextBox>
@code {
//...
}
I try to put ASP.NET Core Razor page programming model to existing Blazor web-app Create.cshmtml
@page "/Create"
@model RazorPagesMovie.Pages.CreateModel
@{
ViewData["Title"] = "Create";
}
<h1>Create</h1>
<h4>Movie</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form method="post">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Movie.Title" class="control-label"></label>
<input asp-for="Movie.Title" class="form-control" />
<span asp-validation-for="Movie.Title" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Movie.ReleaseDate" class="control-label"></label>
<input asp-for="Movie.ReleaseDate" class="form-control" />
<span asp-validation-for="Movie.ReleaseDate" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Movie.Genre" class="control-label"></label>
<input asp-for="Movie.Genre" class="form-control" />
<span asp-validation-for="Movie.Genre" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Movie.Price" class="control-label"></label>
<input asp-for="Movie.Price" class="form-control" />
<span asp-validation-for="Movie.Price" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-primary" />
</div>
</form>
</div>
</div>
<div>
<a asp-page="Index">Back to List</a>
</div>
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
Create.cshmt.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.Rendering;
using acc133blazor.Models;
namespace RazorPagesMovie.Pages
{
public class CreateModel : PageModel
{
private readonly foo.Models.fooContext _context;
public CreateModel(foo.Models.fooContext context)
{
_context = context;
}
public IActionResult OnGet()
{
return Page();
}
[BindProperty]
public Movie Movie { get; set; }
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see https://aka.ms/RazorPagesCRUD.
public async Task<IActionResult> OnPostAsync()
{
if (!ModelState.IsValid)
{
return Page();
}
_context.Movie.Add(Movie);
await _context.SaveChangesAsync();
return RedirectToPage("./Index");
}
}
}
I am not sure it can run success. I try debug web-app, go to Razor page https://localhost:44303/Create
and error.
But its Blazor componets set is still not sufficiency (in beta, just 12 components https://demos.devexpress.com/blazor/ ), I try to add ASP.NET Razor page, or ASP.NET Core Control (ASP.NET Core ViewComponent https://demos.devexpress.com/ASPNetCore/), Can I do this?