ASP.NET MVC定位从cshtml生成的cs文件? [英] ASP.NET MVC locating cs files generated from cshtml?

查看:191
本文介绍了ASP.NET MVC定位从cshtml生成的cs文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我最近开始使用ASP.NET MVC4.我正在使用剃刀引擎. 我的问题是关于带有后缀cshtml的视图文件.在我看来,这些都是由razor预编译为* .cs文件的,然后又被编译为MSIL. (这是我作为JSP开发人员时所熟悉的一种模式.)之所以做出这个假设,一个原因是,如果我在cshtml文件中输入一些无效的c#代码,则会得到如下所示的编译错误:

So I've recently started with ASP.NET MVC 4. I'm using the razor engine. My question is concerning the view files, with suffix cshtml. It seems to me that these are precompiled into *.cs files by razor which in turn are then compiled into MSIL. (A pattern that is familiar from my days as a JSP developer.) One reason why I am making this assumption is that if I enter some invalid c# code into the cshtml file I get a compilation error displayed like this:

第34行:公共类_Page_Views_BaseDataAdmin_Index_cshtml:...

Line 34: public class _Page_Views_BaseDataAdmin_Index_cshtml : ...

第34行并不表示cshtml文件中的错误位置,就像_Page_Views_BaseDataAdmin_Index_cshtml类似乎是指常规.net类而不是视图文件一样.

And line 34 is not indicative of where the error is in the cshtml file, just as the class _Page_Views_BaseDataAdmin_Index_cshtml seems to refer to a regular .net class not the view file.

所以我的问题是:在哪里找到cs文件?具体来说,在上面的示例中,"_ Page_Views_BaseDataAdmin_Index_cshtml.cs"?也许我需要添加一些配置来告诉MVC将此.cs文件保留在磁盘上,如果可以,我该怎么做?

So my question is: Where do I find the cs file? Specifically, in the example above, "_Page_Views_BaseDataAdmin_Index_cshtml.cs"? Maybe I need to add some config to tell MVC to keep this .cs file on disk, if so, how do I do this?

谢谢!

推荐答案

您可以在"ASP.NET临时文件"文件夹中找到已编译的视图.

You can find the compiled views in your Temporary ASP.NET Files folder.

首先找到与您的视图相对应的.compiled文件(例如:home.cshtml): home.cshtml.a8d08dba.compiled

First find the .compiled file that corresponds to your view (ex: home.cshtml): home.cshtml.a8d08dba.compiled

此文件包含程序集名称: assembly ="App_Web_hkc53urb"

This file contains the assembly name: assembly="App_Web_hkc53urb"

您的.cs文件将是程序集名称,并带有数字: App_Web_hkc53urb.1.cs

Your .cs file will be the assembly name concatenated with a number: App_Web_hkc53urb.1.cs

一种更简单的方法可能是使用Windows搜索在临时ASP.NET目录中查找视图名称.

An easier approach might be to use Windows search for your view name in the temp ASP.NET directory.

这篇关于ASP.NET MVC定位从cshtml生成的cs文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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