Hello,
I'm using custom editor to create/view appointments on scheduler.
My appointments has two custom fields (one from dropdownlist and other from Textbox).
Although, I am able to show the fields on custom editor without any problem, the values are not retrieved from Model. Either when the apponitment is created from custom editor.
I am newbie on this and i don't find any clue on Internet.
Could someone help me?
My main view:
@(Html.Kendo().Scheduler<pruebaCalendario.Models.EventoCalendario>
()
.Name("calendario")
.Date((DateTime)ViewBag.FechaRef)
.Views(views =>
{
views.MonthView(monthview => monthview.Selected(true));
views.YearView();
})
.Selectable(true)
.Editable(e => e
.TemplateName("_customEditorTemplate")
.Window(w => w.Title("Vacaciones")
//.Width(800)
)
)
.Messages(m => m
.Save("Guardar")
.AllDay("Todo el día")
.Cancel("Cancelar")
.ResetSeries("Borrar")
.Destroy("Borrar")
//.Date("Fecha")
.Next("Siguiente")
.Previous("Previo")
//.Search("Buscar")
.Today("Hoy")
)
//.EventTemplateId("event-template")
//.Timezone("Etc/UTC")
.BindTo(Model)
.Resources(resource =>
{
resource.Add(m => m.Tipo)
.Title("Tipo")
.Name("comboTipo")
.DataTextField("Text")
.DataValueField("Value")
.BindTo((System.Collections.IEnumerable)ViewBag.Tipo);
})
.DataSource(d => d
.Model(m =>
{
m.Id(f => f.Id);
m.Field("Title", typeof(string)).DefaultValue("No title");
m.Field("Start", typeof(DateTime)).DefaultValue(DateTime.Now);
m.Field("End", typeof(DateTime)).DefaultValue(DateTime.Now);
m.Field("Description", typeof(string));
// m.Field("recurrenceID", typeof(int));
// m.Field("recurrenceRule", typeof(string));
// m.Field("recurrenceException", typeof(string));
// m.Field("isAllDay", typeof(bool));
// m.Field("startTimezone", typeof(string));
// m.Field("endTimezone", typeof(string));
m.Field("Tipo", typeof(string));
m.Field("Observaciones", typeof(string));
})
.Read("Details", "Vacaciones")
.Create("Create","Vacaciones")
)
.Events(ev => ev.Navigate("onNavigate").DataBound("onFinish"))
)
My custom editor view:
@model pruebaCalendario.Models.EventoCalendario
@using pruebaCalendario.Models
@{
//required in order to render validation attributes
ViewContext.FormContext = new FormContext();
}
@functions{
public Dictionary<string, object> generateDatePickerAttributes(
string elementId,
string fieldName,
string dataBindAttribute,
Dictionary<string, object> additionalAttributes = null)
{
Dictionary<string, object> datePickerAttributes = additionalAttributes != null ? new Dictionary<string, object>(additionalAttributes) : new Dictionary<string, object>();
datePickerAttributes["id"] = elementId;
datePickerAttributes["name"] = fieldName;
datePickerAttributes["data-bind"] = dataBindAttribute;
//datePickerAttributes["required"] = "required";
datePickerAttributes["style"] = "z-index: inherit;";
return datePickerAttributes;
}
}
<div class="k-edit-label">
Inicio:
</div>
<div data-container-for="start" class="k-edit-field">
@(Html.Kendo().DatePickerFor(model => model.Start)
.HtmlAttributes(generateDatePickerAttributes("startDateTime", "start", "value:start")))
@*<span data-bind="text: startTimezone"></span>*@
<span data-for="start" class="k-invalid-msg"></span>
</div>
<div class="k-edit-label">
Final:
</div>
<div data-container-for="end" class="k-edit-field">
@(Html.Kendo().DatePickerFor(model => model.End)
.HtmlAttributes(generateDatePickerAttributes(
"endDateTime",
"end",
"value:end",
new Dictionary<string, object>() {{"data-dateCompare-msg", "End date should be greater than or equal to the start date"}})))
@*<span data-bind="text: endTimezone"></span>*@
<span data-for="end" class="k-invalid-msg"></span>
</div>
<div class="k-edit-label">
Tipo:
</div>
@{ var x = Model.Tipo; }
<div data-container-for="tipo" class="k-edit-field">
@(Html.Kendo().ComboBoxFor(model => model.Tipo)
.Name("comboTipo")
.DataTextField("Text")
.DataValueField("Value")
.BindTo((System.Collections.IEnumerable)ViewBag.Tipo)
)
</div>
<div class="k-edit-label">
Observaciones:
</div>
<div data-container-for="observaciones" class="k-edit-field">
@(Html.Kendo().TextAreaFor(model => model.Observaciones)
.Rows(3)
)
</div>
@{
ViewContext.FormContext = null;
}
My EventoCalendario class (It is used to manage the appointments)
using Kendo.Mvc.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace pruebaCalendario.Models
{
public class EventoCalendario : ISchedulerEvent
{
public string Title { get; set; }
public DateTime Start { get; set; }
public DateTime End { get; set; }
public string Description { get; set; }
public bool IsAllDay { get; set; }
public string StartTimezone { get; set; }
public string EndTimezone { get; set; }
public string RecurrenceRule { get; set; }
public string RecurrenceException { get; set; }
public int Id { get; set; }
public string Tipo { get; set; }
public string Observaciones { get; set; }
public EventoCalendario()
{
}
public EventoCalendario(PeriodoVacaciones per)
{
this.Id = per.id;
this.Title = per.usuario;
this.Description = per.Tipo;
this.IsAllDay = per.Tipo == "ENT" ? true : false;
this.Start = per.fechaIni == null ? DateTime.Now : DateTime.Parse(per.fechaIni.ToString());
this.End = per.fechaFin == null ? DateTime.Now : DateTime.Parse(per.fechaFin.ToString());
this.Tipo = per.idTipo;
this.Observaciones = per.observaciones;
}
}
}
I'm sure that it have an easy answer but I'm unable to find it :_(
Thx in advance
KR