I am using RazorGenerator with generator as template for console application. My cshtml file looks like below:
Model has DocumentRefNumber property which is string. Now if DocumentRefNumber is null then it throws exception when trying to do TransformText. I know one solution is to use nullsafe guard like
@Model.DocumentRefNumber != null ?
@Model.DocumentRefNumber : string.Empty. But I don't want to do this way as I don't like to write this nullsafe guard condition in cshtml file for every string property in Model.
CsHtml file:
@* Generator : Template *@
@functions {
public PrintHeaderDto Model { get; set; }
}
@using Harmony.Dto.Print
<!DOCTYPE html >
<html >
<head id="Head1" runat="server">
<title></title>
</head>
<body >
<div id="printHeader">
<h2>@Model.DocumentRefNumber</h2>
</div>
</body>
</html>