When I try to convert date to string I get this error. So how can I fix this error ?
Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.
Here is my view:
<div class="editor-field">
@Html.TextBoxFor(x => x.date.ToString("MM-dd-yyyy"), new { @class = "date", @required = "required" })
@Html.ValidationMessageFor(model => model.date)
</div>
Then I have edited my class with the annotation then same result here is my class. My date parameter in my database table which name is “contents” which I used in my view “x=>x.date”
public class Common
{
[DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}")]
public DateTime date { get; set; }
public class CommonModel
{
public content content{ get; set; }
}
}
Try This:
1) Put Data Annotation in your class like:
2) Replacing this line:
for this should work: