Quantcast
Channel: Telerik Forums RSS
Viewing all articles
Browse latest Browse all 94857

Model fields not populated in Update action

$
0
0

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
 
<ulclass="errors"></ul>
 
<divclass="editor-label">
    @Html.LabelFor(m => m.​User)
</div>
 
<divclass="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>
 
<divclass="editor-label">
    @Html.LabelFor(m => m.January)
</div>
 
<divclass="editor-field">
    @Html.EditorFor(m => m.January)
    @Html.ValidationMessageFor(m => m.January)
</div>
 
<divclass="editor-label">
    @Html.LabelFor(m => m.February)
</div>
 
... snipped for brevity ...
 
<divclass="editor-field">
    @Html.EditorFor(m => m.February)
    @Html.ValidationMessageFor(m => m.February)
</div>
 
<
<divclass="editor-label">
    @Html.LabelFor(m => m.December)
</div>
 
<divclass="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.

 


Viewing all articles
Browse latest Browse all 94857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>