I have a webpage that displays a a table of data pulled back from a sql server view via entity framework and WCF Services.
On my sql server view one of the columns is a Date Field. I am having some difficulty getting it to display without the time part on my page (the time part if not there on the DB but from reading it seems as it is a DateTime property when I generate my entity view the time part will be added.
So basically on my model I have the following (obv the names are just mocked here):
Model
public List<MySqlView> MySqlView { get; set; }
Controller
model.MySqlView = MyWCFService.GetMeAlltheData(
//pass in some values start date, end date
);
So on this I can see everything I want returning fine and then I pass the model to my view.
To build up my table then in the View I am doing the following:
cshtml
<tbody>
@foreach (var item in Model.MySqlView)
{
<tr>
<td class="table-data">
@Html.DisplayFor(modelItem => item.Date)
</td>
//More stuff in table close loop
I have tried item.Date.ToShortDateString()
but that throws exception
Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.