Model fields not populated in Update action

2 posts, 0 answers
  1. Craig
    Craig avatar
    1 posts
    Member since:
    Sep 2015

    Posted 15 Sep 2015 Link to this post


    I have a frustrating issue with fields in my model not being populated in the Update action callback in my controller.  The model:

    public class CountsPerMonthModel
       public int Id { get; set; }
       public UserModel User { get; set; }
       public int January { get; set; }
       public int February { get; set; }
       public int March { get; set; }
       public int April { get; set; }
       public int May { get; set; }
       public int June { get; set; }
       public int July { get; set; }
       public int August { get; set; }
       public int September { get; set; }
       public int October { get; set; }
       public int November { get; set; }
       public int December { get; set; }

    The User property is being correctly populated.  Integer fields January through December are not.

    The callback:

    public ActionResult CountsPerMonthUpdate([DataSourceRequest] DataSourceRequest request, CountsPerMonthModel model)
       // model has User set, but January through December are always 0
       // digging into request, the values are set correctly

    And finally, the code for the popup template:

    @model App.Models.​CountsPerMonthModel
    <ul class="errors"></ul>
    <div class="editor-label">
        @Html.LabelFor(m => m.​User)
    <div class="editor-field">
        @(Html.Kendo().DropDownListFor(m => m.​User)
            .OptionLabel("Select ​user...")
            .DataSource(source =>
                source.Read(read =>
                    read.Action("Get​Users", "Management", new { includeReadOnly = false });
        <p>@Html.Label("​Counts Per Month")</p>
    <div class="editor-label">
        @Html.LabelFor(m => m.January)
    <div class="editor-field">
        @Html.EditorFor(m => m.January)
        @Html.ValidationMessageFor(m => m.January)
    <div class="editor-label">
        @Html.LabelFor(m => m.February)
    ... snipped for brevity ...
    <div class="editor-field">
        @Html.EditorFor(m => m.February)
        @Html.ValidationMessageFor(m => m.February)
    <div class="editor-label">
        @Html.LabelFor(m => m.December)
    <div class="editor-field">
        @Html.EditorFor(m => m.December)
        @Html.ValidationMessageFor(m => m.December)
    @Html.HiddenFor(m => m.Id)

    When given a populated model, the values are displayed correctly in each field, it is only when Update is clicked, any updated values in the fields are not populated into the model object in the callback.

    Any thoughts on what the issue might be?  I've used similar code in other places, this is the first time though that any fields have been an int type, so am wondering if I'm missing something somewhere...

    Also, the editor template for Integer is as follows:

    @model int?
    @(Html.Kendo().IntegerTextBoxFor(m => m)
          .HtmlAttributes(new { style = "width:100%" })





  2. Rosen
    Rosen avatar
    3253 posts

    Posted 16 Sep 2015 Link to this post

    Hello Craig,

    Unfortunately, I'm not able to re-create such issue locally using the provided information. Therefore, it will be appreciated if you could provide a small sample, which demonstrates the issue in question. This will allow us to observe the issue and provide you with more-to-the-point answer.

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top