How can i user TextBoxFor for nullable type, in my case DateTime?
<%:Html.TextBoxFor(m => m.LeaseDate.Value.ToShortDateString(), new { @class = "def-text-input datetime-input" })%>
I try this, but get error :
Exception Details: System.InvalidOperationException: Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.
TextBoxForshould be used for a property on your ViewModel:If you want to format your date, you can use the
DataFormatStringproperty on theDisplayFormatattribute on your ViewModel: