哪里剃刀code出路在哪里? [英] Where Does Razor Code Go?

查看:114
本文介绍了哪里剃刀code出路在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我创建一个Web窗体项目,我的code后面被编译成一个DLL,它是由一个IIS服务器处理。当我使用的JavaScript,它是由浏览器PTED间$ P $,我可以找到使用的东西,如Chrome开发者工具,或通过检查源吧。

When I create a Web Forms project, my code behind is compiled into a DLL, which is processed by an IIS server. When I use Javascript, it's interpreted by the browser and I can find it using things like the Chrome Developer Tools or by inspecting the source.

然而,当我使用剃刀语法创建一个ASP.NET网页,我找不到任何地方的code。由于它不需要进行编译,这不是投入一个DLL,并使用Chrome的检查工具,我找不到它的任何痕迹。

However, when I create an ASP.NET Web Page using Razor syntax, I can't find the code anywhere. Since it doesn't need to be compiled, it's not put into a DLL and I can't locate any trace of it using Chrome's inspect tools.

所以,哪里剃刀code去了?

So, where does Razor code go?

推荐答案

他们确实是在运行时编译。你可以找到一个生成的code文件和临时的DLL在同一个地方,编译web表单放置:

They are indeed compiled at runtime. You can find a generated code file and temporary DLLs in the same place that compiled web forms are placed:

C:\Windows\Microsoft.NET\Framework64\<version>\Temporary ASP.NET Files\<app>\

您可以还可以与该项目的其他部分来检测你的观点错误一起使编译。请参阅:可以剃刀意见编译?这将增加解决方案(在我的经验)的编译时间,但它的检测将被忽视,直到运行时错误是伟大的。我打开它需要的时候。

You can also can enable compilation along with the rest of the project to detect errors in your views. See: Can Razor Views Be Compiled?. This will increase the compilation time of the solution (in my experience), but it's great for detecting errors that would go unnoticed until runtime. I switch it on when needed.

剃刀解析器/发电机code包含在System.Web.Razor项目/组件(可作为MVC源的一部分)。由于最终的结果是一个C#类,C#编译器presumably从那里处理它,因为它任何其他类。

The Razor parser/generator code is contained in the System.Web.Razor project/assembly (available as part of the MVC source). Since the end result is a c# class, the c# compiler presumably handles it from there as it would any other class.

生成的code为视图看起来类似(在我的项目之一,从重置密码页面摘录)。

The generated code for a view looks something like (excerpted from a "reset password" page in one of my projects).

namespace ASP {
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Net;
    using System.Web;
    using System.Web.Helpers;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.WebPages;
    using System.Web.Mvc;
    using System.Web.Mvc.Ajax;
    using System.Web.Mvc.Html;
    using System.Web.Routing;

    public class _Page_Areas_Anonymous_Views_Home_ResetPassword_cshtml : System.Web.Mvc.WebViewPage<Web.UI.Areas.Anonymous.ResetPasswordViewModel> {

#line hidden

        public _Page_Areas_Anonymous_Views_Home_ResetPassword_cshtml() {
        }

        protected ASP.global_asax ApplicationInstance {
            get {
                return ((ASP.global_asax)(Context.ApplicationInstance));
            }
        }

        public override void Execute() {

    const string title = "Reset Password";
    ViewBag.Title = title;


BeginContext("~/Areas/Anonymous/Views/Home/ResetPassword.cshtml", 302, 63, true);

WriteLiteral("</h1>\r\n            </div>\r\n        </div>\r\n    </div>\r\n    <div");

EndContext("~/Areas/Anonymous/Views/Home/ResetPassword.cshtml", 302, 63, true);

BeginContext("~/Areas/Anonymous/Views/Home/ResetPassword.cshtml", 365, 12, true);

WriteLiteral(" class=\"two\"");

EndContext("~/Areas/Anonymous/Views/Home/ResetPassword.cshtml", 365, 12, true);

BeginContext("~/Areas/Anonymous/Views/Home/ResetPassword.cshtml", 377, 15, true);

WriteLiteral(">\r\n        <div");

EndContext("~/Areas/Anonymous/Views/Home/ResetPassword.cshtml", 377, 15, true);

BeginContext("~/Areas/Anonymous/Views/Home/ResetPassword.cshtml", 392, 19, true);

WriteLiteral(" class=\"banner-box\"");

EndContext("~/Areas/Anonymous/Views/Home/ResetPassword.cshtml", 392, 19, true);

BeginContext("~/Areas/Anonymous/Views/Home/ResetPassword.cshtml", 411, 5, true);

WriteLiteral(">\r\n\r\n");

            #line default
            #line hidden

             using( @Html.BeginForm( "ResetPassword", "Home", FormMethod.Post, new { id = "main-form" } ) )
            {

                Write(Html.ValidationSummary());

// etc. etc. Even simple views result in a large code file

这篇关于哪里剃刀code出路在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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