Monday, December 15, 2014

Editor Template for Boolean Property in Razor

If you want to display 2 radio buttons for a boolean property in Razor with Yes and No labels, this is how you could do it.

Create your own editor template and put it in the Shared/EditorTemplate folder.

Template code:

@model bool
@using System.Web.Mvc
@Html.RadioButtonFor(model=>model, false) No
@Html.RadioButtonFor(model => model, true) Yes