作为嵌入资源的 C# 视图在构建后始终显示旧视图
我有一个 MVC2 网站,它使用其他程序集的视图。 为此,我将视图标记为“嵌入式资源”。
我能够看到视图,但现在,当我更改视图时,我再也看不到更改了。
我将视图称为嵌入式资源的方式与此类似:
return View("~/Extension/Extensions.MyExtension.dll/" +
"Extensions.MyExtension.Views.MyItem.Details.ascx", entity);
在本例中,“扩展”部分指示视图必须作为嵌入式资源加载。以下部分指示包含视图的程序集。最后一部分是视图的位置(包括命名空间)。
当我更改视图的全部内容后,为什么仍显示早期视图中的数据。或者甚至取消将视图标记为嵌入资源。
为了确保我拥有 Extensions.myExtension.dll 的最新程序集,我将该程序集复制到网站的 bin 文件夹中。我用反射器检查了装配体,看看装配体中是否有正确的视图。这是正确的观点,但我仍然看到旧的观点。
更改视图的名称可以暂时解决问题,但这对我来说不是一个好的解决方案。当我将视图名称更改回原来的名称时,会显示旧视图。
I have a MVC2 website which uses views from other assemblies.
To do this, I marked the view as "Embedded Resource".
I was able to see the view but now, when I change the view I can't see the changes anymore.
The way I call the view as an embedded resource is similar to this:
return View("~/Extension/Extensions.MyExtension.dll/" +
"Extensions.MyExtension.Views.MyItem.Details.ascx", entity);
in this case the "Extension" part is indicating that the view must be loaded as embedded resource. The following part indicates the assemblies which contains the view. The last part is the location of the view (including namespace).
How can it be that data from an earlier view is still shown after I change the entire content of the view. Or even unmark the view as embedded resource.
To make sure I have the latest assembly of Extensions.myExtension.dll I copied the assembly to the bin folder of the website. I checked the assembly with reflector to see if the correct view is in the assembly. This is the correct view but I still see the old view.
Changing the name of the view resolves the problem temporary, but is not I good solution for me. When I change name of the view back to what is was, the old view was shown.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在我看来,如果数据被缓存并且 DLL 文件没有被视为已更改,则几乎如此。您的 web.config 中是否有“optimizeCompilations”属性?检查是否设置为 false。否则(如果为 true)仅重新编译更改的 DLL 文件。
可以在此 MSDN 页面上找到更多信息。
例如:
Almost seems to me if data is cached and the DLL files aren't being seen as changed. Do you have the property 'optimizeCompilations' in your web.config? Check if it's set to false. Otherwise (if true) only changed DLL-files are recompiled.
More information can be found on this MSDN page.
For example:
您可能需要重新编译项目,因为视图在编译时嵌入到生成的程序集中。如果您只是更改 ASCX 文件而不重新编译,那么如果您只是刷新浏览器,更改将不会生效。
You might need to recompile the project because views are embedded into the resulting assembly at compile time. If you simply change the ASCX file without recompiling changes won't take effect if you simply refresh your browser.
您需要重建完整的项目。如果这也不能解决问题,请清理项目,然后构建。
You need to rebuild your complete project. If that also doesn't solve the problem, Clean the project and then build.