I have a model that contains information about an event
public class EventModel
{
public int EventId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public DateTime StartDate { get; set; }
public DateTime RevenueStartDate { get; set; }
}
My view also contains a kendo grid to display a list of facilities associated with the event. One or more facilities can be associated with this model. However, there is no property to contain the list of associated facilities. I plan to handle that in the DataSource's transport methods. The Grid will contain just a list of facility names and will allow users to add additional facilities to the list (via the DataSource's create transport. Below is what I have so far but the create transport never gets called.
var ds = new kendo.data.DataSource({
transport: {
read: {
cached: false,
url: '@Url.Action("ReadAllFacilities", "Tactic")',
dataType: "json"
}
}
});
var OrgdataSource = new kendo.data.DataSource({
transport: {
read: {
url: '@Url.Action("ReadFacilities", "Tactic")',
dataType: "json"
},
create: {
url: '@Url.Action("Facility", "Tactic")',
type: "POST",
dataType: "json"
}
},
batch: false
schema: {
model: {
id: "Value",
fields: {
id: { type: "string", editable: false },
Text: { type: "string" }
}
}
}
});
$("#FacilityGrid").kendoGrid({
dataSource: OrgdataSource,
autoBind: true,
autoSync: true,
editable: { mode: "inline" },
selectable: true,
toolbar: ["save", "create"],
columns: [
{ command: ["destroy"], title: " ", width: "150px" },
{ field: "Text", title: "Facility Name", editor: OrgDropDownEditor },
]
});
function OrgDropDownEditor (container, options) {
$('<input required data-text-field="Text" data-value-field="Value" data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList({
autoBind: true,
dataSource: ds
});
}
And my controller Code:
[HttpPost]
public JsonResult AddFacility(SelectListItem newFacility)
{
...//THIS CODE NEVER GETS CALLED
}
[HttpGet]
public string ReadAssociatedFacilities(int id)
{
var lst = new List<SelectListItem>();
lst = dataProvider.GetAssociatedFacilities();
var json = new JavaScriptSerializer().Serialize(lst);
return json;
}
[HttpGet]
public string ReadAllFacilities()
{
var lst = new List<SelectListItem>();
lst.Add(new SelectListItem() { Value = "0", Text = "Facility 1" });
lst.Add(new SelectListItem() { Value = "1", Text = "Facility 2" });
var json = new JavaScriptSerializer().Serialize(lst);
return json;
}