Model Data Not Present when passing from View to Controller

6 posts, 1 answers
  1. James
    James avatar
    40 posts
    Member since:
    Sep 2014

    Posted 30 Sep 2014 Link to this post

    I have a MVC application where I am passing a data model to the view and then when I click the submit button I want to pass the model back to the controller.  When I receive the model in the controller it contains no data.  I am using the "MaskedTextBoxFor()" for most fields and then a "DatePickerFor()".

    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,
  2. Answer
    Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 01 Oct 2014 Link to this post

    Hi James,

    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.

     
  3. James
    James avatar
    40 posts
    Member since:
    Sep 2014

    Posted 01 Oct 2014 in reply to Atanas Korchev Link to this post

    Thanks for the reply.  That seems to do the trick.  So, Name() is not required for Kendo?
  4. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 01 Oct 2014 Link to this post

    Hi,

    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.

     
  5. Vinod
    Vinod avatar
    3 posts
    Member since:
    Jun 2017

    Posted 19 Jul in reply to Atanas Korchev Link to this post

    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.

  6. Bozhidar
    Admin
    Bozhidar avatar
    1140 posts

    Posted 21 Jul Link to this post

    Hello Vinod,

    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
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top