This is a migrated thread and some comments may be shown as answers.

Model fields not populated in Update action

1 Answer 50 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Craig
Top achievements
Rank 1
Craig asked on 15 Sep 2015, 05:08 AM

Hi,

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
{
   [Editable(false)]
   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:

[HttpPost]
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>
 
<div class="editor-field">
    @(Html.Kendo().DropDownListFor(m => m.​User)
        .Name("​User")
        .OptionLabel("Select ​user...")
        .DataTextField("DisplayName")
        .DataValueField("UserId")
        .DataSource(source =>
        {
            source.Read(read =>
            {
                read.Action("Get​Users", "Management", new { includeReadOnly = false });
            });
        })
    )
</div>
 
<div>
    <p>@Html.Label("​Counts Per Month")</p>
</div>
 
<div class="editor-label">
    @Html.LabelFor(m => m.January)
</div>
 
<div class="editor-field">
    @Html.EditorFor(m => m.January)
    @Html.ValidationMessageFor(m => m.January)
</div>
 
<div class="editor-label">
    @Html.LabelFor(m => m.February)
</div>
 
... snipped for brevity ...
 
<div class="editor-field">
    @Html.EditorFor(m => m.February)
    @Html.ValidationMessageFor(m => m.February)
</div>
 
<
<div class="editor-label">
    @Html.LabelFor(m => m.December)
</div>
 
<div class="editor-field">
    @Html.EditorFor(m => m.December)
    @Html.ValidationMessageFor(m => m.December)
</div>
 
@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%" })
      .Min(int.MinValue)
      .Max(int.MaxValue)
)

 

Thanks,

Craig.

 

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 16 Sep 2015, 12:28 PM

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.

Regards,
Rosen
Telerik
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
Tags
Grid
Asked by
Craig
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or