Good evening everyone,
i know this question is old, but i couldnt solve it with other questions like here: How do I convert a C# List<string[]> to a Javascript array?. I am quite new to this.
I want to use the array in my javascript, to show the datepicker on which dates are events. My script(datepicker.js):
$(document).ready(function() {
var array = []; //array that should be filled with dates like this ["29-09-2015", "..."]
$("#datepicker").datepicker({
numberOfMonths: 3,
beforeShowDay: function (date) {
if ($.inArray($.datepicker.formatDate('yy-mm-dd', date), array) > -1) {
return [false, "", " no"];
}
else {
return [true, "", "yes"];
}
}
});
});
My Controller looks like this:
public ActionResult Index(int EID = 0, int CID = 0, int IID= 0)
{
var dates = db.Histories.Where(p => p.SiteId == EID && p.CId == CID && p.IId == IID).Select(p => SqlFunctions.StringConvert((double)
SqlFunctions.DatePart("m", p.Date)).Trim() + "-" +
SqlFunctions.DateName("dd", p.Date) + "-" +
SqlFunctions.DateName("yyyy", p.Date));
dates = dates.OrderBy(u => u.Length);
int datescount = dates.Count();
List<string> sList = new List<string>();
for(int i =0; i<datescount; i++)
{
sList.Add(dates.Skip(i).First());
}
return View();
}
In the controller the list sList contains the dates i want to show as events.
In the view the datepicker, which i can already see, will be called like this:
Date: <div id="datepicker"></div>
So now i want to send the list to the script and convert it there to an array. Could you explain me how to do it?
On the other page i didnt understand what Romoku meant with:
//View.cshtml
<script type="text/javascript">
var arrayOfArrays = JSON.parse('@Html.Raw(Model.Addresses)');
Do i have to transfer the list to a model, if i use json? What is with the IDs? How to transfer them to the json method?