stuart-d2
12/16/2014 - 9:08 PM

Checking Whether a Model String is Null, then injecting conditional outcome into HTML ASP Content. To prevent passing a null at runtime. Th

Checking Whether a Model String is Null, then injecting conditional outcome into HTML ASP Content. To prevent passing a null at runtime. This can crash the site, sometimes throwing a ArgumentOutofRange statement.
The string is passed in as a parameter to the IsNullOrEmpty method. If true, make the content blank (thus preventing passing a null, and just leaving a blank area on the site). If false (i.e., it does return a value) inject the content from the model. Last, inject var into the content into the html <%= %>

 <h4><%= cashbackLine %></h4>
                    <% var offerDescription = String.IsNullOrEmpty(offer.Description) ? offer.Description = "" : offer.Description = string.Format(Global.OnXModelsFormat, offer.Description.Substring(0, offer.Description.LastIndexOf('-')));%>
                    <h4><%= offerDescription %></h4>