0

I am trying to make a website using Fullcalendar scheduler plugin and want to be able to use the items from my Model to fill in the "Resources".

the resources-function looks like this:

resources: [
        { id: 'room01', title: 'Room 1' },
        { id: 'room02', title: 'Room 2' },
        ],

But I want to be able to do something like this:

resources: [
@foreach (var item in model) 
{
{ id: item.id, title: item.firstname };
}
        ],

However its not working and I cant really understand why. I tried using parenthesis to make it look the same like this:

"{ id: '" + item.id + ", title: '"+  item.firstname + " }"

but its not working. I am very new to coding and never used advanced commands like this before. Please advice how I could solve this.

  • 1
    You can use `var model = @Html.Raw(Json.Encode(Model))` to convert your model to a JavaScript array, so you should have a view model containing a `IEnumerable resources` property where `T` contains properties `string id` and `string title` –  Oct 06 '18 at 06:38
  • Refer also [these answers](https://stackoverflow.com/questions/23781034/razor-mvc-populating-javascript-array-with-model-array) for some other options –  Oct 06 '18 at 06:40
  • Allright, thanks. I'll look into that. – Huberth Lindkvist Oct 06 '18 at 13:57

0 Answers0