简体   繁体   English

ASP.NET MVC3中的编译错误

[英]Compilation Error in ASP.NET mvc3

<div class="dateAdded">Article submitted @article.DateAdded.ToRelativeDateStringUtc()</div>

Compiler Error Message: CS1061: 'System.DateTime' does not contain a definition for 'ToRelativeDateStringUtc' and no extension method 'ToRelativeDateStringUtc' accepting a first argument of type 'System.DateTime' could be found (are you missing a using directive or an assembly reference?) 编译器错误消息:CS1061:'System.DateTime'不包含'ToRelativeDateStringUtc'的定义,并且找不到扩展方法'ToRelativeDateStringUtc'接受类型为'System.DateTime'的第一个参数(您是否缺少using指令或组装参考?)

Here is where my error is occurring. 这是我发生错误的地方。 I have a class that contains ToRelativeDateStringUtc() included in my program. 我的程序中包含一个包含ToRelativeDateStringUtc()的类。 Is this a MS class that I have to import? 这是我必须导入的MS类吗? I do not see it listed anywhere in the .net reference list. 我没有在.net参考列表中的任何位置看到它。 I'm sure its something simple, does anyone have any ideas? 我敢肯定这很简单,有人有想法吗?

I have already added the folder to my webconfig that includes the class, which contains the method the program is "missing". 我已经将文件夹添加到了包含类的webconfig中,该类包含程序“丢失”的方法。 So its not missing it... I just dont know what else to do from here. 因此,它没有丢失……我只是不知道从这里还能做什么。

There are several things you could try. 您可以尝试几种方法。

Firstly, you can try the using directive inside the view you use this in: 首先,您可以在以下视图中尝试using指令:

@using Your.Namespace.Where.Extension.Class.Is.Located

Secondly, the web.config you've added the namespace to is probably the global one. 其次,您添加了名称空间的web.config可能是全局名称空间。 If this view is inside an Area.. try putting the namespace into the web.config that is inside that particular area. 如果此视图位于Area中,请尝试将名称空间放入该特定区域内的web.config中。

The first one will work regardless. 无论如何,第一个都可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM