I am trying to use a NumericTextBox with a nullable decimal. When the numeric text box is left blank, the default "The field <field name> must be a number" message appears.
How can I submit the data with an empty NumericTextBox to pass a null value to my controller?
Thanks!
How can I submit the data with an empty NumericTextBox to pass a null value to my controller?
Thanks!
9 Answers, 1 is accepted
0
Hello Jon,
I am not able to reproduce such behavior. Could you please check the attached project and see if I missed something?
If I did please modify the project and send it back so we can search for a solution.
Kind regards,
Petur Subev
the Telerik team
I am not able to reproduce such behavior. Could you please check the attached project and see if I missed something?
If I did please modify the project and send it back so we can search for a solution.
Kind regards,
Petur Subev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jon
Top achievements
Rank 1
answered on 07 Nov 2012, 08:16 PM
I guess it is more than just the numeric text box. It also has to do with using it in a grid popup editor.
I have updated your project with the issue. If you try to add a person and leave the salary blank, you will see the error.
Thanks.
EDIT: Well, I can't re-attach the updated project because it exceeds the 2MB limit. All I did was add a grid and an EditorTemplate for the Person object.
EditorTemplates\Person.cshtml:
Grid in Index.cshtml
I have updated your project with the issue. If you try to add a person and leave the salary blank, you will see the error.
Thanks.
EDIT: Well, I can't re-attach the updated project because it exceeds the 2MB limit. All I did was add a grid and an EditorTemplate for the Person object.
EditorTemplates\Person.cshtml:
@model KendoMVCWrappers.Models.Person
@Html.LabelFor(m => m.Name):<
br
/>
@Html.EditorFor(m => m.Name)
@Html.ValidationMessageFor(m => m.Name)
<
br
/><
br
/>
@Html.LabelFor(m => m.BirthDate):<
br
/>
@Html.Kendo().DatePickerFor(m => m.BirthDate)
@Html.ValidationMessageFor(m => m.BirthDate)
<
br
/><
br
/>
@Html.LabelFor(m => m.Salary):<
br
/>
@Html.Kendo().NumericTextBoxFor(m => m.Salary)
@Html.ValidationMessageFor(m => m.Salary)
<
br
/><
br
/>
Grid in Index.cshtml
@(Html.Kendo().Grid<KendoMVCWrappers.Models.Person>()
.Name(
"Persons"
)
.HtmlAttributes(
new
{ style =
"height:200px;"
})
.Scrollable()
.Columns(columns =>
{
columns.Bound(p => p.Name);
columns.Bound(p => p.Salary);
})
.ToolBar(tb => tb.Create().Text(
"Add Person"
))
.Editable(editable => editable
.Mode(GridEditMode.PopUp)
.Window(win => win.Title(
"Add Person"
))
)
.DataSource(ds => ds
.Ajax()
.Model(model =>
{
model.Id(p => p.PersonID);
model.Field(p => p.PersonID).Editable(
false
);
})
.Create(create => create.Action(
"CreatePerson"
,
"Home"
))
.Read(read => read.Action(
"ReadPersons"
,
"Home"
))
)
)
0
Jesse
Top achievements
Rank 1
answered on 07 Nov 2012, 08:32 PM
I don't know if this is the kind of solution you are looking for, but I was able to get around this problem by specifying a default value on those fields:
@(Html.Kendo().Grid<
MyModel
>()
.Name("grid")
@* other settings here *@
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>
{
model.Id(m => m.MyModelId);
model.Field(f => f.Salary).DefaultValue(0);
})
)
)
0
Jon
Top achievements
Rank 1
answered on 07 Nov 2012, 08:39 PM
@Jesse,
Thanks, but that's not really what I'm looking for. I need to the value to be null, not zero. By setting a default value, the value is in the numeric text box when creating the record.
When not being used as part of the editor in the grid, it allows submission with an empty (null) value. When added to the editor, it will return an error...
Thanks, but that's not really what I'm looking for. I need to the value to be null, not zero. By setting a default value, the value is in the numeric text box when creating the record.
When not being used as part of the editor in the grid, it allows submission with an empty (null) value. When added to the editor, it will return an error...
0
Tomasz
Top achievements
Rank 1
answered on 17 Jan 2013, 09:54 PM
I have same problem. If a property in model is set to etc. decimal? , i can`t save data on the grid.
I need to leave it as null , and I can`t .
If I set property in model as string type then it is fine, but it cant be done in my case.
How to solve this problem ?
I need to leave it as null , and I can`t .
If I set property in model as string type then it is fine, but it cant be done in my case.
How to solve this problem ?
0
Hello Tomasz,
Could you update the project and send it within a support ticket referencing this forums thread so we can take a look?
Thank you for the understanding.
Kind regards,
Petur Subev
the Telerik team
Could you update the project and send it within a support ticket referencing this forums thread so we can take a look?
Thank you for the understanding.
Kind regards,
Petur Subev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jon
Top achievements
Rank 1
answered on 22 Jan 2013, 01:53 PM
I have created ticket # 651165 with an updated project that shows the issue.
Thanks.
Thanks.
0
Accepted
Tomasz
Top achievements
Rank 1
answered on 22 Jan 2013, 02:38 PM
I upgrade to new release and it seems to work fine in my project
0
Jon
Top achievements
Rank 1
answered on 23 Jan 2013, 04:58 PM
Thanks Tomasz, the upgrade corrected the issue. That is the same response I received from support.