Click here to Skip to main content
15,915,324 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I want to cutomize a calendar template and for which I have a model:--

C#
public class TimeSlotModel
    {
        public long Id { get; set; }
        public DayOfWeek DayOfWeek { get; set; }
        public string StartHour { get; set; }
        public string EndHour { get; set; }
    }


these fields are save in db and now i want to use these entries in my calendar.js,
So how i use the model values in javascript template.

Thanks
Posted
Updated 25-Nov-13 19:39pm
v2
Comments
manoj.jsm 26-Nov-13 1:34am    
Hi You Can Using JSON Data pass to Model Value to JS
Member 9534579 26-Nov-13 2:04am    
No my controller is like this:
[HttpGet]
public ActionResult Calendar()
{
var model = this.instructorService.GetAllTimeSlots();

var viewModel = ModelMapper.Map<ilist><timeslot>, IList<timeslotmodel>>(model);

return this.View(viewModel);
}

From this i got the value of all fields in viewModel but not in html page.
manoj.jsm 26-Nov-13 2:27am    
Dude if ur using FullCalendar Js
you can try this link:
http://growingtech.blogspot.in/2012/02/full-calendar-with-json-data-source.html
http://stackoverflow.com/questions/11310013/passing-fullcalander-events-via-json-to-controller
http://stackoverflow.com/questions/1544010/jquery-full-calendar-not-showing-events?rq=1

1 solution

Hi,
If you want to use model value in javascript,then you need to access model value like this

var modelJSValue = '@Model.Id';(Razor code) or '<%: Model.Id %>'

Now your modelJSValue will have value of ID that belongs to your model.

Updated solution:
XML
<script>
        jQuery(document).ready(function () {
            // initiate layout and plugins
            App.init();
            var modelJSValue = '@Model.Id';
alert(modelJSValue); //Confirm and see what we get at this point.
            Calendar.init(modelJSValue); //Pass modelJSvalue to your script
});
</script>


Note: Make sure you read the parameter value in your js file as well.
Hope this helps you a bit.

Regards,
RK
 
Share this answer
 
v3
Comments
Member 9534579 26-Nov-13 2:03am    
I am already try this but can you plz tell me where I put this...in my cshtml page where i call javascript...
<script>
jQuery(document).ready(function () {
// initiate layout and plugins
App.init();
Calendar.init();
var modelJSValue = '@Model.Id';
});
</script>

or in calendar.js...

var Calendar = function () {


return {
//main function to initiate the module
init: function () {
Calendar.initCalendar();
},

initCalendar: function () {

if (!jQuery().fullCalendar) {
var modelJSValue = '@Model.Id';
//var id=document.getElementById("Id")
//var modelId = '@Model[0].Id'
//var modelName = '@Model[0].StartHour'
//var modelName = '@Model[0].EndHour'
//var modelName = '@Model[0].DayOfWeek'
return;
}
---
----

Actuly I apply these things but still no result.
♥…ЯҠ…♥ 26-Nov-13 2:10am    
Updated my solution.. try it and lemme know
Member 9534579 26-Nov-13 4:47am    
Thanks this helps me i got a Id value in html.cs page but it still not pass in the calendar.js I write like this....

var Calendar = function () {
return {
//main function to initiate the module
init: function () {
Calendar.initCalendar();
},
initCalendar: function (modelValue)
{
modelJSValue = modelValue;
alert('modelValue');
if (!jQuery().fullCalendar)
{
return;
}
var date = new Date();
var d = date.getDate();
--- ......
---- .....

here alert didn't show id value(parameter value)... it show only:modelJSValue
Member 9534579 26-Nov-13 4:26am    
Thanks this helps me i got a Id value in html.cs page but it still not pass in the calendar.js I write like this....

var Calendar = function () {


return {
//main function to initiate the module
init: function () {
Calendar.initCalendar();
},

initCalendar: function (modelValue) {
modelJSValue = modelValue;
alert('modelValue');
if (!jQuery().fullCalendar) {
return;
}

var date = new Date();
var d = date.getDate();
---
----

here alert show didn't show id value...
♥…ЯҠ…♥ 26-Nov-13 4:49am    
init: function (modelIDVal) {
Calendar.initCalendar(modelIDVal);
}
and in initCalendar: alert(modelValue);(remove quotes)

Now try......

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900