I’m working on an MVC 5 project where a manager can view when the people in his department are on leave.
I’m able to do an initial load from the database for all departments.
But when I select an item from the dropdownlist it won’t load that data in an new scheduler instance. Instead the Data method only outputs that AJAX call to the browser (when I get the results to the data actionresult) or it won’t load the new data (when i get the results to the index).
After spending days in the documentation figuring out how to do the filtering in this specific case.
I’m overlooking something but I’ve lost the overview to complete this on my own.
Any specific help would be greatly appreciated.
The Index Controller:
public ActionResult Index(string AfdelingsId)
{
var scheduler = new DHXScheduler();
scheduler.Skin = DHXScheduler.Skins.Flat;
scheduler.Config.first_hour = 6;
scheduler.Config.last_hour = 20;
scheduler.LoadData = true;
scheduler.EnableDataprocessor = true;
scheduler.EnableDynamicLoading(SchedulerDataLoader.DynamicalLoadingMode.Month);
//var nameValuepair = GetCollection();
Afdeling afdeling = new Afdeling();
ViewBag.AfdelingsId = new SelectList(db.Afdeling, "Id", "AfdelingNaam", afdeling.Id);
return View(scheduler);
}
The Data controller:
public ActionResult Data(string AfdelingsId)
{//events for loading to scheduler
//int? afdelingsId = 3;
//foreach (var item in formCollection.AllKeys)
//{
// var value = formCollection[item];
//}
List<VerlofDTO> verlofAll = new List<VerlofDTO>();
if (AfdelingsId == null)
{
verlofAll = VerlofViewModel.GetVerlofAll();
}
else
{
var afdId = Int16.Parse(AfdelingsId);
verlofAll = VerlofViewModel.GetVerlofAfdeling(afdId);
}
return new SchedulerAjaxData(verlofAll);
}
the View:
@using (Html.BeginForm(“Index”, “Schedules”, FormMethod.Get))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Verlof</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@*@Html.LabelFor(model => model.Medewerker.AfdelingsId, "AfdelingsId", htmlAttributes: new { @class = "control-label col-md-2" })*@
<div class="col-md-10">
@Html.DropDownList("AfdelingsId", null, htmlAttributes: new { @class = "form-control" })
@*@Html.ValidationMessageFor(model => model.Medewerker.AfdelingsId, "", new { @class = "text-danger" })*@
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Vraag verlof op" class="btn btn-default"/>
</div>
</div>
<div class="scheduler_container">
@Html.Raw(Model.Render())
</div>
</div>
}