VS2017:为什么 razor 项目仍然指的是 MVC? [英] VS2017: Why razor project still refers to MVC?

查看:38
本文介绍了VS2017:为什么 razor 项目仍然指的是 MVC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 ASP.NET Core 2.0 的 MVC 和 razor 项目非常困惑.在 Visual Studio 2017 中,我执行以下操作:

I'm very confused about MVC and razor projects for ASP.NET Core 2.0. In Visual Studio 2017 I do the following:

  • 新项目
  • Web ASP.NET Core 应用程序 (C#)
  • Web 应用程序(不是 Web 应用程序 MVC)

但是当我打开一个页面的 cs 代码时,我看到:

But when I open the cs code of a page I see:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.RazorPages;  // <------- MVC?

namespace WebApplication2.Pages
{
    public class AboutModel : PageModel
    {
        public string Message { get; set; }

        public void OnGet()
        {
            Message = "Your application description page.";
        }
    }
}

如果我选择了一个 razor only 项目,为什么它仍然指的是 MVC?

Why it still refers to MVC if I selected a razor only project?

我的问题来自一个更深层次的问题:我不明白我必须遵循哪些文档!当我看到有关 razor 或 MVC 的教程时,我不确定它是否适用于此类项目.

My question rises from a deeper problem: I don't understand what documentation I have to follow! When I see a tutorial about razor or MVC I'm not sure if it applies to this type of project.

推荐答案

这仅仅是因为 Microsoft.AspNetCore.Mvc 命名空间是微软团队决定放置 Razor 的地方.这并不意味着您的项目使用 MVC,只是它使用的某些类位于名称中包含 MVC 的名称空间中.

This is simply because the Microsoft.AspNetCore.Mvc namespace is where the microsoft team decided to put Razor. It doesn't mean that your project uses MVC, just that some classes it uses are located in a namespace that contains MVC in its name.

这只是一个猜测,但我相信这可能只是一个历史性的事情.Razor 曾经真的只是 MVC 的一部分,所以它在 MVC 命名空间下,但现在它不需要 MVC 来生存,他们将它留在这里是为了兼容性或一致性?这个问题可能只有来自微软的人才能回答:-/

It is just a guess, but I believe it could simply be a historic thing. Razor used to really be just part of MVC, so it was under the MVC namespace but now that it doesn't need MVC to live they left it here for compatibility or consistency ? This question can probably only be answered by someone from microsoft :-/

这篇关于VS2017:为什么 razor 项目仍然指的是 MVC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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