How to Display HTML with MVC’s NullDisplayText Attribute

Adding DisplayFormat attribute to model’s property allows you to set formatting options for that property’s value. One of options is NullDisplayText, where you can set what to display if the value is null.

Sometimes you may wish to have NullDisplayText return a piece of HTML. To be able to render this HTML correctly, you need to set HtmlEncode value to false.

[DisplayFormat(NullDisplayText = "<div>My HTML<div>", HtmlEncode = false)]
public int? MyProperty { get; set; }

Hide URL Path When Printing in Chrome

When you print (or print preview) web page in Chrome, printout will include URLs for each link on the page.

For example, if you have a link “Back to Homepage”, when printed it will display as “Back to Homepage (”.

To stop URLs being printed, add the following style –

 <style media="print">
        content:none !important;