01.
@model Keying.Models.Invoice
02.
03.
@using (Html.BeginForm("Shipment", "Home", FormMethod.Post, new
04.
{
05.
@class = "form-horizontal",
06.
role = "form",
07.
id = "submitForm",
08.
myInvoice = Model
09.
}))
10.
{
11.
<
label
>
12.
Invoice Number
13.
</
label
>
14.
@(Html.TextBoxFor(model => model.InvoiceNumber)
15.
)
16.
17.
<
label
>
18.
Invoice Date
19.
</
label
>
20.
21.
@(Html.Kendo().DatePickerFor(model => model.ShipDate)
22.
.Name("ship_date")
23.
.Value(DateTime.Today)
24.
)
25.
26.
<
label
>
27.
Bill to Account
28.
</
label
>
29.
30.
@(Html.Kendo().MaskedTextBoxFor(model => model.BillAccount)
31.
.Name("bill_account")
32.
)
33.
}
1.
public ActionResult Shipment(Invoice myInvoice, string button)
2.
{
3.
var shipment = new Shipment();
4.
// other processing
5.
return View(shipment);
6.
}
So with the code snippets above the Invoice Data model going to the view is populated with some data but when it returns to the controller it contains no data.
Thanks,
7 Answers, 1 is accepted
Try not setting the Name of the kendo windgets as it will break ASP.NET MVC model binding:
@(Html.Kendo().DatePickerFor(model => model.ShipDate)
.Value(DateTime.Today)
)
Regards,
Atanas Korchev
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
When you use DatePickerFor (or *For) the Name() is set internally to the property name specified in the expression. So if you use Kendo().DatePicker() you need to set Name() but when you use Kendo().DatePickerFor() you don't as it is set automatically. More info is available here.
Regards,
Atanas Korchev
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
html:
<h2>calendar event</h2>
<div id="scheduler"></div>
js:
<script>
$(function () {
$("#scheduler").kendoScheduler({
date: new Date(),
height: 600,
views: [
"day",
{ type: "month", selected: true },
"week",
"month",
],
timezone: "Etc/UTC",
dataSource:{
transport: {
read:
{
url: "/Validation/GetCalendarEvents",
dataType: "json"
},
update: {
url: "/Validation/UpdateCalendarEvent",
dataType: "json",
type:"POST"
},
create: {
url: "/Validation/SaveCalendarEvent",
type: "POST",
},
destroy: {
url: "/Validation/DeleteCalendarEvent",
dataType: "json",
type: "POST",
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
alert(kendo.stringify(options.models));
return { models: kendo.stringify(options.models) };
}
}
},
batch:true,
schema: {
data: "data",
model: {
id: "taskId",
fields: {
taskId: { from: "TaskID", type: "number" },
title: { from: "title", defaultValue: "No title", validation: { required: true } },
start: { type: "date", from: "startdate" },
end: { type: "date", from: "enddate" },
startTimezone: { from: "StartTimezone" },
endTimezone: { from: "EndTimezone" },
description: { from: "Description" },
recurrenceId: { from: "RecurrenceID" },
recurrenceRule: { from: "RecurrenceRule" },
recurrenceException: { from: "RecurrenceException" },
ownerId: { from: "OwnerID", defaultValue: 1 },
isAllDay: { type: "boolean", from: "IsAllDay" }
}
}
},
}
});
});
</script>
the above i have used to create scheduler event. I have created a table having name 'Events'
sql scripts:
create table Events(
taskId int primary key,
title varchar(100),
startdate date,
enddate date,
startTimezone datetime,
endTimezone datetime,
description varchar(100),
recurrenceId int,
recurrenceRule varchar(100),
recurrenceException int,
isAllDay bit
)
insert into Events values(1,'new','7/18/2017','7/18/2017',null,null,'newly',null,null,null,1)
I am able to fetch the data but when i am updating or creating it is not taking model to controller
Please help me out
Thanks in advance.
I've opened a separate support ticket for your issues, since it's not relevant for the current thread. Let's continue our discussion there.
Regards,
Bozhidar
Progress Telerik
If I comment out the .Name() parameter, then I cannot render the page:
Server Error in '/' Application.
Value cannot be null.
Parameter name: keyDescription: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: key
My problem is that the selected month/year isn't returned to the controller using ASP.NET MVC.
<div class="col-sm-3 style=" margin-top: auto"">
@(Html.Kendo().DatePicker()
.Name("monthpicker")
.Start(CalendarView.Year)
.Depth(CalendarView.Year)
.Format("MMMM yyyy")
.Value(Model.StartDate)
.DateInput()
.HtmlAttributes(new { style = "width: 90%" })
)
@Html.ValidationMessageFor(model => model.StartMonth, "", new { @class = "text-danger" })
</div>
[HttpPost]
public ActionResult SaveReportBuilder(ReportBuilderVM model)
{
//model shows null StartDate
...
}
StartMonth is defined as
[DataType(DataType.Date)]
[Display(Name = "Start Month")]
public DateTime? StartMonth { get; set; }
Controller initializes it to:
rb.StartMonth = DateTime.Today;
Any help would be appreciated.
Thanks
Found the solution:
@(Html.Kendo().DatePickerFor(model => model.StartDate)
.Start(CalendarView.Year)
.Depth(CalendarView.Year)
.Format("MMMM yyyy")
.Value(DateTime.Today)
.DateInput()
.HtmlAttributes(new { style = "width: 90%" })