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

Editing a grid with a PercentTextBox doesn't save empty values.

3 Answers 50 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Makoto
Top achievements
Rank 1
Makoto asked on 19 May 2011, 04:24 PM
I have a grid, and one of the columns is a percent value.  In my view model, I am specifying that it should use my custom percent editor control:
[UIHint("Percent")]
public decimal? PercentObligation { get; set; }

And the Percent control looks like this:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Nullable<double>>" %>
<%= Html.Telerik().PercentTextBox()
        .Name(ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty))
        .InputHtmlAttributes(new { style = "width:100%" })
        .MaxValue(100)
        .MinValue(0)
        .DecimalDigits(4)
        .Spinners(false)
        .Value(Model)
%>

This actually works just fine and I'm able to show the percent control and change values and save them just fine.  However, the problem is when I don't have a value. 

I was looking at the POST variables when I save changes to my grid and noticed that it only POSTs the "PercentObligation" field only if there is a value in there.  If there is no value, then that field is never sent in the POST.  I would expect it to post that field without a value, but it doesn't. 

Since I am using MVC's built-in UpdateModel() method, it doesn't properly update my model since it didn't receive a new value for PercentObligation.

Is this a known bug?

3 Answers, 1 is accepted

Sort by
0
tom
Top achievements
Rank 1
answered on 10 Apr 2012, 11:07 AM
Yes this is happening to me to. To me this is a bug, but these Telerik number controls do not really support Nullable values which is a shame.

My workaround is to check Request.Form for the property (or your model if you have it in your Update(MyModel model) action) after the call to Update, if it is null you know you can then update the db object to null.

Tom.
0
Ricardo
Top achievements
Rank 1
answered on 05 Dec 2012, 01:39 PM
It's happening the same thing to me too.

Does it has a workaround?
0
Maciel
Top achievements
Rank 1
answered on 03 May 2013, 06:37 PM
So... 

Someone has a solution?
Tags
Grid
Asked by
Makoto
Top achievements
Rank 1
Answers by
tom
Top achievements
Rank 1
Ricardo
Top achievements
Rank 1
Maciel
Top achievements
Rank 1
Share this question
or