I have a template for Views along with a lot of jQuery that extracts input from EditorFor. For this reason, I would rather use mine EditorForrather than use something like<input type="text">
Now I have implemented datepicker , and all I need is an attribute IDso that it can do its magic ( $('#datepicker').datepicker();), so I'm wondering if there is a way to force a IDin the editor for?
Here is my attempt so far.
@Html.EditorFor(modelItem => item.ReleaseDate, new {@id ="datepicker" })
And if this “should” work, is there something else that might cause the problem?
I use a tag <input>for modal in the same view that uses this datepicker is just fine, so I know that it works, but I just can't get EditorForto work with it.
Thanks!
EDIT: @ForEachwhich accepts each element, which adds a datepicker to the releaseDate of each element. (2 tddown)
@foreach (var item in Model)
{
<tr>
<td class="col-lg-2">
<span class="item-display">
<span style="font-size: 17px;">
@Html.DisplayFor(modelItem => item.Name)
</span>
</span>
<span class="item-field">
@Html.EditorFor(modelItem => item.Name)
</span>
</td>
<td class="col-lg-3">
<span class="item-display">
<span style="font-size: 17px;">
@Html.DisplayFor(modelItem => item.ReleaseDate)
</span>
</span>
<span class="item-field">
@Html.TextBoxFor(modelItem => item.ReleaseDate, new {@id="datepicker"})
@*@Html.EditorFor(modelItem => item.ReleaseDate, new {@id ="datepicker" })*@
</span>
</td>
<td class="col-lg-3">
<span class="item-display">
<span style="font-size: 17px; font-style:italic">
@Html.DisplayFor(modelItem => item.Description)
</span>
</span>
<span class="item-field">
@Html.EditorFor(modelItem => item.Description)
</span>
</td>
<td class="col-lg-3 col-lg-offset-1">
<span style="visibility:hidden" class="ID col-lg-1">@Html.DisplayFor(modelItem => item.ID)</span>
<span class="item-edit-button">
<button type="button" onclick="editFunction(this)" class=" btn btn-warning col-lg-3 col-lg-offset-0"><span style="margin-right: 5px" class="glyphicon glyphicon-pencil"></span>Edit</button>
</span>
<span class="item-save-button">
<button type="button" onclick="saveFunction(this)" class="btn btn-success col-lg-3 col-lg-offset-4"><span style="margin-right: 5px" class="glyphicon glyphicon-trash"></span>Save</button>
</span>
<span class="item-delete-button">
<button class="btn btn-danger col-lg-3 col-lg-offset-3" data-toggle="modal" data-target="#@item.ID" onclick="deleteStart(this)">
<span style="margin-right: 5px" class="glyphicon glyphicon-trash"></span>Delete
</button>
</span>
<div class="modal fade" id="@item.ID" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" style="background-color: #d9534f">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel" style="font-size: 30px; font-style:oblique; color:white">Delete</h4>
</div>
<div class="modal-body">
<span style="font-size: 20px">Are you sure you want to delete movie: @Html.DisplayFor(modelItem => item.Name)?</span>
</div>
<div class="modal-footer">
<button type="button" onclick="deleteStopped(this)" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" style="margin-right:10px" onclick="deleteFunction(this)" class="btn btn-danger">Delete</button>
</div>
</div>
</div>
</div>
</td>
</tr>
<tr>
<td colspan="12">
<p style="font-size: 17px; font-style: italic; font-family: 'Roboto', sans-serif">
Movie ID: @Html.DisplayFor(modelItem => item.ID)
<br />
Placeholder
</p>
</td>
</tr>
}
source
share