ASP.NET MVC 2 - Html.Editor ¿Para un tipo anulable?
Tengo dos plantillas de editor: una para decimal y otra para decimal. (anulable)
Pero cuando tengo un decimal anulable en mi modelo, intenta cargar el editor decimal normal:
<%: Html.EditorFor(model => model.SomeDecimal )%>
<%: Html.EditorFor(model => model.SomeNullableDecimal )%>
El primero funciona bien y carga la plantilla del editor decimal. El segundo también intenta cargar la plantilla decimal (y falla porque no es un campo decimal).
El mensaje de error es:
The model item passed into the dictionary is null, but this dictionary requires
a non-null model item of type 'System.Decimal'.
Mis plantillas se declaran así:
Plantilla decimal:
<%@ Control Language="C#"
Inherits="System.Web.Mvc.ViewUserControl<System.Decimal>" %>
Plantilla decimal anulable:
<%@ Control Language="C#"
Inherits="System.Web.Mvc.ViewUserControl<System.Decimal?>" %>
Sé que puedo hacerlo funcionar pasando el nombre de la plantilla, p. Ej.
Pero realmente preferiría que funcionara automáticamente usando el tipo al igual que todas las otras plantillas.
<%: Html.EditorFor(model => model.SomeNullableDecimal,
"NullableDecimalTemplate" )%>