在同一项目中合并MVC + Blazor [英] Combining MVC + Blazor in the same project

查看:111
本文介绍了在同一项目中合并MVC + Blazor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们当前的应用程序现在正在ASP.NET Core(MVC)上运行,我想知道在同一项目中是否有一种正式的方法来使用MVC和Blazor(客户端)?

Our current application is now running on ASP.NET Core (MVC) and I was wondering is there will be an offical way to use MVC and Blazor (client side) in the same project?

之所以要这样做,是因为我们无法从MVC迁移到Blazor,因为应用程序太大了.我正在考虑从MVC到Blazor的逐步过渡.只是不确定这是否可能吗?

The reason why I want to do that is because we won't be able to migrated from MVC to Blazor in one big bang since, the application is just too big. I was thinking on a step by step transition from MVC to Blazor. Just not sure if this will be possible?

推荐答案

对于服务器端Blazor,(该博客中的示例)提供了一个确切的示例.

This is definitely now possible for server-side Blazor, Chris Sainty's blog (and the source for the example in that blog) gives an example of exactly how to do that.

我个人更喜欢将Blazor组件放在与MVC项目相同的解决方案中的单独项目中.造成这种情况的原因有几个:

Personally I prefer to have the Blazor components in a separate project in the same solution as the MVC project. There are a few reasons for that:

  • 我发现Blazor项目的启动速度比MVC快
  • 我只设法使项目的自动重建(基本热重装)在Blazor项目中工作,而不在MVC项目中工作
  • 我发现能够隔离Blazor组件以确保问题与页面的MVC部分无关,这很有用.

我倾向于将Blazor项目设置为启动项目进行初始调试,然后在准备将组件集成到MVC页面时切换到MVC项目.

I tend to do the initial debugging with the Blazor project set as the startup project and then switch to the MVC project when I'm ready to integrate the component into an MVC page.

如果您想尝试这种方法,请回答我的问题

If you want to try that approach, my answer to the question Adding Server-Side Blazor to an existing MVC Core app gives a complete walk through of how to add a separate Blazor project to an existing solution that contains an MVC project, and then how to use those Blazor components in the MVC project.

我希望客户端Blazor也可以采用类似的方法,但是我还没有尝试过.

I expect very similar approaches would apply for client-side Blazor too, but I haven't tried that yet.

这篇关于在同一项目中合并MVC + Blazor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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