RazorLight: Child template just does not render in a couple of scenarios after .NET 2.0 upgrade
Just upgraded to .NET 2.0 beta 1. It is working, compiling, etc. But in a couple of scenarios, my child HTML template just does not render. In the generated HTML there’s just nothing there, also no errors.
E.g. this used to work in 1.1, not anymore in 2.0:
<tr style="@(rs.ActivityBookings == null || rs.ActivityBookings.Count == 0 ? "display:inherit" : "display:none")">
And when using a foreach, I now have to check if there are more than zero items. Without that check, again nothing rendered.
This is quite frustrating as this is trial and error, with no clue why this is not working. Am I doing something wrong?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 35 (3 by maintainers)
Commits related to this issue
- #134 - Fix IncludeAsync rendering issues — committed to toddams/RazorLight by toddams 6 years ago
@toddams When do you guess the nuget package will be released for this fix?
Nothing was reported until now. We do recycle our app pool everyday anyway. Our service is not very loaded at the moment. We are sending ~250 rendered email per month right now
@toddams , are you ok with https://github.com/wik8wz/RazorLight/commit/35f06da97ec7da7677379932397560410a44d04b implementation? Will you accept PR with it? We are also using his branch in a couple of projects without any issues.
Commit 0dbc5e1d174411530c3ab81db94dfc3444dd4a4d does not fix rendering issue. It is still occurring for large templates. The problem is caused by MemoryPoolViewBufferScope implementation (clearing/passing/returning the buffer). I implemented workaround here https://github.com/wik8wz/RazorLight/commit/35f06da97ec7da7677379932397560410a44d04b
I found the bug, and that is a total disaster!) Can’t imagine how we’ve been using this for such a long time without facing this bug. It happens with big templates
Will prepare the next release, thank you for the very detailed description
@jzabroski we are not having any issues with the partial views with big templates ever since we switched to using the branch that @wik8wz created a long time ago. We have just been using his source code in our solution we have it as a project and we can debug as needed. We did have an issue with the cache yesterday, but so far after a rebuild and re-deploy it appears to be working fine. We are scheduled to go into Production this weekend.
I’m waiting on @toddams to give me access to update the Nuget package, then within a few days I should be able to fix all these problems. He gave me write access to the repo, but not the nuget feed.
@wik8wz Why sadly? Friend request me on LinkedIn, who knows, maybe if you love C# I would love to work with you.
Thanks for your help!
@jzabroski I created one here: https://github.com/toddams/RazorLight/pull/275 Sadly I’m no longer working with C# and therefore will no longer support development here. I hope this works for you (I saw there are no merge conflicts)
I recently requested write access to this repo form @toddams in order to help out with the project and get a few key bugs fixed.
@wik8wz Do you have any interest in a pull request for your fix? I’d rather you formally submit one than me copy-paste your contribution, on legal grounds.
@markleacompassphs in meantime we usage of service in production increased significantly to 1000s emails per month. Did not face rendering issue again since fix was implemented (over 8 months now). Quite happy how it is working to be honest.
Big thanks to wik8wz for fixing this issue. We are using your branch and no longer have the partial view issues that we were facing. Another interesting thing we found was that you need to be careful about making var assignments inside of the partial views, you are better served to just directly looking into your model for all of your data.
I hit what sounds like this bug today… sorry for the formatting… could not quite get i right… so the point in the bottom HTML is missing as the error is not visible…
Fairly simple main view:
<html lang="en"> <head> <link rel="stylesheet" href="~/Bootstrap/css/bootstrap.css" /> <title>@Model.Definition.Name</title> </head> <body> @{ await IncludeAsync("..\\StandardItems\\TournamentHeader.cshtml", (Model.Data as TMServerDb.Models.Core.MatchSet).Tournament); }@using Microsoft.EntityFrameworkCore.Internal @using RazorLight @using TMServerDb.Models.Core @inherits RazorLight.TemplatePage<TMServerAPI.Models.Reporting.ReportViewModel> @{ DisableEncoding = true; } <!doctype html>@{ var ms = Model.Data as TMServerDb.Models.Core.MatchSet; var grouped = ms.Matches.OrderBy(n => n.Number).ThenBy(p => p.Pitch.Name).GroupBy(s => s.PlannedStart); </body> </html>
The nested view:
@using RazorLight @using TMServerDb.Models.Core @inherits RazorLight.TemplatePage<IGrouping<DateTime, TMServerDb.Models.Core.Match>>When rendering, in my test, I have 30 odd groupings… but only a few make it to the pdf… intercepting the result from the rendering, explains why… notice the numerous ending of html and body tags…
<html lang="en"> <head> <link rel="stylesheet" href="~/Bootstrap/css/bootstrap.css" /> <title>Tournament Schedule</title> </head> <body> <div><!doctype html>Amsterdam Open 2019
Uithoorn
01-06-2019 - 02-06-2019
</div></body> </html>
</body> </html>
</body> </html>
</body> </html>
</body> </html>
</body> </html>
</body> </html>
@wik8wz Can you open a PR from your fork with the fix?