正在设置页面加载的模型值
本文关键字:模型 加载 设置 | 更新日期: 2023-09-27 18:26:42
有没有办法在页面加载时设置模型值。因为我需要它来用模型值填充模式。我尝试了document.readyAjax调用来获取模型,但它告诉我,在ajax调用发生之前,模型没有任何价值。
这是代码,你可以看到我是如何试图填充模式的,但它不会达到的功能
<script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")"> </script>
<script src="@Url.Content("~/Scripts/kendo/kendo.all.min.js")"></script>
<script>
$(document).ready(function () {
$.ajax({
url: '/Team/Calendar/PopulateCalendar/',
type: "POST",
data: $(this).serialize(),
});
});
$(function () {
$("#scheduler").kendoScheduler({
date: new Date("2013/6/13"),
startTime: new Date("2013/6/13 07:00 AM"),
height: 600,
views: [
"day",
{ type: "week", selected: true },
"month",
"agenda"
],
timezone: "Etc/UTC",
dataSource: {
batch: true,
transport: {
read: {
url: "/Team/Calendar/PopulateCalendar/",
dataType: "json"
},
update: {
url: "http://demos.kendoui.com/service/tasks/update",
dataType: "jsonp"
},
create: {
url: "http://demos.kendoui.com/service/tasks/create",
dataType: "jsonp"
},
destroy: {
url: "http://demos.kendoui.com/service/tasks/destroy",
dataType: "jsonp"
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
return { models: kendo.stringify(options.models) };
}
}
},
schema: {
model: {
id: "taskId",
fields: {
taskId: { from: "@Model.CalendarItems.Select(calendar=> calendar.TaskId)", type: "number" },
title: { from: "@Model.CalendarItems.Select(calendar=> calendar.Title)", defaultValue: "No title", validation: { required: true } },
start: { type: "date", from: "@Model.CalendarItems.Select(calendar => calendar.Start)" },
end: { type: "date", from: "@Model.CalendarItems.Select(calendar => calendar.End)" },
startTimezone: { from: "@Model.CalendarItems.Select(calendar => calendar.StartTimezone)" },
endTimezone: { from: "@Model.CalendarItems.Select(calendar => calendar.EndTimezone)" },
description: { from: "@Model.CalendarItems.Select(calendar => calendar.Description)" },
recurrenceId: { from: "@Model.CalendarItems.Select(calendar => calendar.RecurrenceId)" },
recurrenceRule: { from: "@Model.CalendarItems.Select(calendar => calendar.RecurrenceRule)" },
recurrenceException: { from: "@Model.CalendarItems.Select(calendar => calendar.RecurrenceException)" },
ownerId: { from: "OwnerID", defaultValue: 1 },
isAllDay: { type: "boolean", from: "@Model.CalendarItems.Select(calendar => calendar.IsAllDay)" }
}
}
},
filter: {
logic: "or",
filters: [
{ field: "ownerId", operator: "eq", value: 1 },
{ field: "ownerId", operator: "eq", value: 2 }
]
}
},
resources: [
{
field: "ownerId",
title: "Owner",
dataSource: [
{ text: "Alex", value: 1, color: "#f8a398" },
{ text: "Bob", value: 2, color: "#51a0ed" },
{ text: "Charlie", value: 3, color: "#56ca85" }
]
}
]
});
我认为您使用的是带有Razor的ASPNET MVC,您应该能够通过Scripplet将您的模型设置为javascript。