Reputation: 109
I am currently using MVC and my attempt is to pass a date picker to a Controller. To do this, I have to set my model as per below:
@Html.TextBoxFor(model => model.aDate, new { @type="date"})
The above code works fine. However I need to use the below html tag and with a javascript to display the pickup list on click instead:
<input type="text" id="datepicker-From" class="form-control">
My question is - is there a way to pass models to the html tag above?
Upvotes: 0
Views: 39
Reputation: 1118
You could simply pass the id
and class
to the @Html.TextBoxFor
like this
@Html.TextBoxFor(model => model.aDate, new { @type="date", @id="datepicker-From", @class="form-control"})
Then you could write a script to target the element on the page load
window.document.onload = function() {
document.getElementById("datepicker-From").addEventListener("click", function(){
//Do your stuff here
});
}
Upvotes: 1