I want to use PersianDatePicker. How can I use it in razor (EditorFor
) instead of <input>
since I want to use viewbag as today date, and set the value using @Model
.
<input type="text" id="Item.FromRequestDate" name="Item.FromRequestDate" onclick="PersianDatePicker.Show(this, '1392/03/22');" class = "form-control form-filter input" />
my base EditorFor
is as below:
@Html.EditorFor(model => model.Item.FromRequestDate, new { htmlAttributes = new { @class = "form-control form-filter input" } })
Update:
As a solution, I did it as below:
(I haven't use EditorFor yet.I have wrote the codes below just as alternative and it's not answer)
Now, I use Item.FromRequestDate
as name and Id for binding value to model.
<input type="text" value="@ViewBag.PersianFromRequestDate" id="Item.FromRequestDate" name="Item.FromRequestDate" onclick="PersianDatePicker.Show(this, '@ViewBag.PersianToday');" class = "form-control form-filter input" />
and in controller I have
ViewBag.PersianFromRequestDate = item.FromRequestDate;
for sending the value from controller separately (and not in model), and
var now = PersianDateTime.Now;
var today = now.ToString(PersianDateTimeFormat.Date);
ViewBag.PersianToday = today;
for today value. Attention that you should use today Viewbag in single cote sign, even if you have send it as string from controller: '@ViewBag.PersianToday'