I want to use strongly typed HTML helpers in ASP.NET MVC 2 with a property of my model that is Nullable<T> .
Model
public class TicketFilter { public bool? IsOpen { get; set; } public TicketType? Type{ get; set; }
View (HTML)
<p>Ticket status: <%: Html.RadioButtonFor(m => m.IsOpen, null) %> All <%: Html.RadioButtonFor(m => m.IsOpen, true) %> Open <%: Html.RadioButtonFor(m => m.IsOpen, false) %> Closed </p> <p>Ticket type: <%: Html.RadioButtonFor(m => m.Type, null) %> Any <%: Html.RadioButtonFor(m => m.Type, TicketType.Question) %> Question <%: Html.RadioButtonFor(m => m.Type, TicketType.Complaint) %> Complaint </p>
However, using helpers in this way throws an ArgumentNullException - the second parameter cannot be null. Instead of null I tried to use new bool?() / new TicketType? as well as String.empty . All of them lead to the same exception. How can I get around this and bind the control to a null value?
nullable asp.net-mvc html-helper asp.net-mvc-2
Brant bobby
source share