ASP.NET MVC强类型的视图编译错误 [英] ASP.NET MVC strongly typed view compilation error
问题描述
这是一个奇怪的。我改变了一些东西(不知道),现在我的应用程序的视图不编译运行时。
This is a strange one. I changed something (not sure what) and now my app's view doesn't compile at runtime.
视图本身是强类型:
<%@ Page Language="C#"
MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<MyNamespace.OperatorModel>" %>
在我访问的页面,它编译失败,他说:
When I visit the page, it fails to compile, saying:
CS1061:'对象'不包含'登录'的定义,并没有扩展方法'登录'接受第一种类型的对象的说法可以找到(是否缺少using指令或程序集引用?)
CS1061: 'object' does not contain a definition for 'Log' and no extension method 'Log' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
pretty的标准误差。相应的源$ C $ C线为:
Pretty standard error. The corresponding source code line is:
<%= Html.HiddenFor(model => model.Log) %>
当我看到编译器生成的code,我看到视图的基类并不强类型:
When I look at the compiler-generated code, I see that the base class of the view is not strongly typed:
[System.Runtime.CompilerServices.CompilerGlobalScopeAttribute()]
public class views_operator_create_aspx
: global::System.Web.Mvc.ViewPage, // NOT STRONGLY TYPED
System.Web.SessionState.IRequiresSessionState,
System.Web.IHttpHandler {
所以我的问题是,是什么原因造成的观点编译器忽略视图定义我的继承
属性?
我要指出的是,同一个控制器上的其他意见的工作,他们有完全按照我上面显示的同一页面的声明。
I should point out that other views on the same controller are working, and they have exactly the same page declaration as I've shown above.
修改有谁知道在哪里生成的源$ C $ C文件生命,假设它的地方依然存在?
EDIT Does anyone know where the generated source code file lives, assuming it is persisted somewhere?
修改我发现罪魁祸首(在我的回答如下),但我不知道为什么会这样。如果有人可以解释我想AP preciate了!
EDIT I found the culprit (in my answer below) but I've no idea why this is happening. If someone can explain I'd appreciate it!
推荐答案
好了,所以我回吐我认为到这一点:
Ok so I pared my view down to this:
<%@ Page Language="C#"
MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<MyNamespace.OperatorModel>" %>
<%@ Import Namespace="MyNamespace.Data" %>
<asp:Content ContentPlaceHolderID="MainContent" runat="server">
<%= GetType() %><br />
<%= GetType().BaseType %><br />
<%= GetType().BaseType.BaseType %>
</asp:Content>
的产量,即使所有内容领域空白:
The output was, even with all content areas empty:
ASP.views_operator_create_aspx
System.Web.Mvc.ViewPage
System.Web.UI.Page
ASP.views_operator_create_aspx
System.Web.Mvc.ViewPage
System.Web.UI.Page
但是,如果我删除&LT;%@导入
行,我得到这样的:
But if I remove the <%@ Import
line, I get this:
ASP.views_operator_create_aspx
System.Web.Mvc.ViewPage`1 [MyNamespace.OperatorModel]
System.Web.Mvc.ViewPage
ASP.views_operator_create_aspx
System.Web.Mvc.ViewPage`1[MyNamespace.OperatorModel]
System.Web.Mvc.ViewPage
我不知道为什么进口应引起页面不再是强类型。有人能解释一下吗?关于如何调试和跟踪编译任何提示将是很好。这是伟大的,我能保持现在的编码,但这不是一个非常令人满意的结束这个问题。
I have no idea why the import should cause the page to no longer be strongly typed. Can someone explain? Any tips on how to debug or trace the compilation would be nice. It's great that I can keep coding now, but this isn't a very satisfying end to the problem.
这篇关于ASP.NET MVC强类型的视图编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!