3
votes

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?

1

1 Answers

1
votes

There's no problem without using Blazor to combine together.

For Blazor, although you could combine it with Razor Pages but the asp-page ,asp-for tag helper will not work any more.

Refer to Blazor Component Embedded in Razor Page

Link to a page with a Blazor component and all of the other page links will no longer function. You can even replicate the same situation using the boilerplate template app for a Blazor Server Side app and linking to any mvc view or razor page. All links no longer work. This has to be a Startup issue. Removing endpoints.MapBlazorHub(); will allow the links to work again but obviously that breaks the Blazor component.

For partial view/view components, they are aslo not working in Blazor, they could be changed to a razor component.

Refer to Can you use a ViewComponent in a Blazor layout

https://github.com/aspnet/Blazor/issues/1066