Im currently build ASP.NET C# MVC App. I am planning to use bootstrap datepicker multidate in html form to let user select several dates (for vacation). The problem is the datepicker write multiple dates in one input field and separated by comma (example: 2016-10-10, 2016-11-10, 2016-13-10). I want to know how to write these dates each for one record in database, along with other input in that form(name,address,etc) that inputted repeatedly like this one:
Here is my model:
public class LeaveApp
{
[Key]
public int LvId { get; set; }
public string LvAppId { get; set; }
public int EmpId { get; set; }
public DateTime LvDate { get; set; }
public string LvPeriod { get; set; }
public string LvDesc { get; set; }
}
And my controller that post into database:
[HttpPost]
public ActionResult Create(/*[Bind(Include = "EmpId,LvAppId,LvPeriod,LvStartDate,LvEndDate,LvDesc,LvCount")]*/ LeaveApplicationViewModels leave)
{
if (leave != null)
{
var a = leave.B.LvAppId;
var b = leave.B.EmpId;
var c = leave.B.LvDate.ToString("yyyy-MM-dd");
var e = leave.B.LvPeriod;
var f = leave.B.LvDesc;
//Value.ToString("yyyy-MM-dd HH:mm:ss")
ViewBag.RowsAffected = db.Database.ExecuteSqlCommand("insert into LeaveApps (LvAppId, EmpId, LvDate, LvPeriod,LvDesc)"+
" values ({0}, {1},{2},{3}, {4})",
"LV0022",b,c, e,f);
}
return RedirectToAction("Index");
}
And my html form that use datepicker:
<div class='input-group date' id="datetimepicker">
@Html.TextBoxFor(model => model.B.LvDate, new { Id = "lv_start_date", @Class = "form-control input-sm" })
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
<script type="text/javascript">
$(function () {
$('#datetimepicker').datepicker({
format: "dd/mm/yyyy",
multidate: 5,
maxViewMode: 1,
multidateSeparator: ",",
orientation: "bottom left",
keyboardNavigation: false,
clearBtn: true,
daysOfWeekDisabled: "0,6",
startDate: new Date()
});
Thankyou for your help,