R# is incorrectly reporting one of my MVC3 views as having an error. I have 2 layouts, each with different sections defined:
@{
Layout = "~/Views/Shared/layout2.cshtml";
}
@section Layout2Section { @* Layout2Section is red, reported as error by R#. *@
<span>Injected into LayoutSection2</span>
}
The view displays fine in a browser. Here is code from layout2:
@RenderSection("Layout2Section", false)
@if (!IsSectionDefined("Layout2Section"))
{
<span>default layout2 section</span>
}
There is another layout view in ~/Views/Shared named _Layout.cshtml, the default in an MVC3 project. R# is only giving intellisense for sections in _Layout.cshtml, not layout2.cshtml. I have tried prefixing with an underscore, it does not work. If I try to define any section in layout2.cshtml that is not defined in _Layout.cshtml, R# is calling it an error. How to disable this, either to tell R# that the view is a section definer, or to get rid of the “1 file with errors” message?
Update
After derigel’s comment, I realized that the above code is not exactly what I have in my project. Specifically, the line that defines the layout uses T4MVC like so:
@{
Layout = MVC.Shared.Views.layout;
}
If I change it to a string as in the original question, the R# error goes away. @Derigel, shall I still create a test project and post to your tracker? I just reproduced the above update in a brand new MVC3 project, after adding the T4MVC lib.
@olivehour Oh, now I get it. It’s known limitation of R# – it can detect layouts only in constant string literals. Can you change T4 templates to generate constants instead of readonly fields?