没有编译,C#如何在Razor视图中运行? [英] How does C# run inside a Razor view without compilation?

查看:185
本文介绍了没有编译,C#如何在Razor视图中运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎在网上找不到答案.

I couldn't seem to find an answer to this on the web.

由于C#是一种编译语言,因此Razor视图中的代码如何能够执行而无需开发人员重新构建?

Since C# is a compiled language, how is code inside a Razor view able to execute without the developer having to build again?

例如,如果我用以下代码加载页面:@{string test = "123";}.

For example, if I load a page with this code: @{string test = "123";}.

但是将代码更改为此:@{string test = "test";}

But then change the code to this: @{string test = "test";}

我不需要重建吗?另外,是否允许这种情况发生C#功能或MVC功能?

How do I not need to rebuild? Also, is the thing that is allowing this to happen a C# feature or an MVC feature?

推荐答案

剃刀引擎基本上可以编译"视图. 像这样...

The razor engine basically "compiles" the view. Something like this...

@model Person
<html>
  <p>
  @Model.FirstName
  </p>
</html>

实际上被编译为类中的方法.我不记得它调用的确切函数,但是看起来像这样:

is actually compiled into a method in a class. I can't remember the exact functions it calls but it would look something along the lines of this:

class RazorPage<T>
{
    T Model;

    void Page
    {
        Write("<html>");
        Write("  <p>");
        Write(Model.FirstName);
        Write("  </p>");
        Write("</html>");
    }
}

这篇关于没有编译,C#如何在Razor视图中运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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