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.
TextBoxFor
should be used for a property on your ViewModel:If you want to format your date, you can use the
DataFormatString
property on theDisplayFormat
attribute on your ViewModel: