MVC3 - What's with the caching of razor views?

2019-06-12 08:11发布

问题:

What is the official line on how to make sure a razor view is rendered as latest? At the moment it appears I am getting a cached version.

I have a view, that renders a partial and this partial renders a template.

Save, compile, iis reset:

Same old view!

Stop it now!

Let me give u an example

@Html.EditorForModel("~/Views/Shared/EditorTemplates/Object.ascx")

Renders Object.ascx

Remove that line renders nothing (good)

Then adding @Html.EditorForModel("~/Views/Shared/EditorTemplates/Huh.cshtml")

Renders Object.ascx

=Insanity.

回答1:

Did you try Ctrl+F5 in your browser? Maybe the html was cached on the client. Also if you are using the [OutputCache] attribute to cache it downstream this could happen.


UPDATE:

After you have posted your code you seem to have overriden the ~/Views/Shared/EditorTemplates/Object.ascx default template. Then you replace this line by:

@Html.EditorForModel("~/Views/Shared/EditorTemplates/Huh.cshtml")

but depending on the model used in Huh.cshtml Object.ascx could still be rendered for some properties.



回答2:

Found it: it has to be called Object.cshtml and no other control called "Object" can live in that folder (e.g. Object.ascx).