现有项目中缺少Blazor功能 [英] Blazor Features missing in existing project

查看:94
本文介绍了现有项目中缺少Blazor功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始在VS 2019中使用新的"Blazor Server App"项目模板,并且一切正常.现在,我尝试在现有的.NET Core 3 ASP.NET MVC应用程序中使用Blazor的某些东西.我添加了".MapBlazorHub();& .AddServerSideBlazor();"进入启动类和

I've started playing around with the new "Blazor Server App" project template in VS 2019 and everything works as expected. Now I've tried to use some Blazor stuff in an existing .NET Core 3 ASP.NET MVC app. I've added ".MapBlazorHub(); & .AddServerSideBlazor();" to the startup class and

< script src ="_ framework/blazor.server.js"></script>

到_layout文件.新的剃须刀组件将按预期方式呈现,并在@code块中触发"OnInitialized()"方法.但是,当我尝试使用按钮单击事件时,什么也没有发生-在VS控制台中没有-在浏览器控制台中没有.经过数小时的研究,我发现两个项目的语法高亮显示有所不同:

to the _layout file. The new razor component gets rendered as expected and the "OnInitialized()" method in the @code block is fired. But when I try to use a button click event nothing happens - not in the VS console - not in the browser console. After some hours of research I've found out that the syntax highlighting is different in the 2 projects:

Microsoft Blazor Server应用程序模板:

Microsoft Blazor Server App template:

现有项目:

我还发现添加-剃刀页面..."上下文菜单仅在MS模板中可见.但是我在csproject或sln文件中找不到任何差异.

Also I found that the "Add - Razor Page..." context menu is only visibible in the MS template. But I can't find any differences in the csproject or the sln file.

我真的很坚持.有什么想法我想念的吗?

I'm really stuck on this. Any ideas what I'm missing?

推荐答案

正如Andreas所说,您需要在文件夹中添加一个新的 _Imports.razor 文件( Views 文件夹或还原剃刀组件的自定义文件夹.

As Andreas has said, you need to add a new _Imports.razor file in your folder( Views folder or your custom folder where you restore your razor components.

_Imports.razor:

_Imports.razor:

@using Microsoft.AspNetCore.Components.Web

结构:

我还发现添加-剃刀页面..."上下文菜单仅在MS模板中可见.但是我在csproject或sln文件中找不到任何差异.

Also I found that the "Add - Razor Page..." context menu is only visibible in the MS template. But I can't find any differences in the csproject or the sln file.

MS模板使用 Pages 文件夹,您可以看到 Add-Razor Page 选项.

The MS template uses Pages folder and you could see Add- Razor Page option.

如果您使用的是Razor Pages项目,则将出现 Add- Razor Page ,因为您使用的是MVC,所以该选项不存在.

If you are using Razor Pages project there will be Add- Razor Page, since you are using MVC, the option does not exist.

如果您使用最新的vs 2019和asp.net core 3.0,则可以通过直接单击 Add-New Item-Razor Component 创建一个剃须刀组件

If you use the latest vs 2019 and asp.net core 3.0, you could create a razor component by clicking Add - New Item - Razor Component directly

这篇关于现有项目中缺少Blazor功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆