I know, that views are compiled on the fly, but when exactly does it happen? First compilation occurs at first request, if I’m not mistaken. But what about when I modify aspx/cshtml file, what happens then?
Is it possible to somehow control this behavior without using aspnet_compiler.exe?
The problem I’m having is that I modify my controller/viewmodel and load them as a separate assembly. When I refresh page I get this error:
The model item passed into the dictionary is of type ‘Test.Controllers.AController+IndexViewModel’, but this dictionary requires a model item of type ‘Test.Controllers.AController+IndexViewModel’.
The difference between these models is the assembly name (not shown in this error), so I need to recompile views against my updated viewmodel.
It happens on the next request after the modification.
If your ASPX Views have codebehind then there’s 2 step compilation happening. First the codebehind class is compiled as part of the project, next the ASP.NET runtime creates another class that inherits from the precompiled class. If you change the controller to pass a different model class but don’t recompile your project it won’t work because the precompiled class still references the class from the old assembly.
So, if you use codebehind, the project compiles a class that inherits from
ViewPage<TModel>, and if you want to changeTModelyou have to recompile the project. If you don’t use codebehind this is not an issue, becauseTModelis determined at runtime.