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

Can't seem to get to bind to model

4 Answers 360 Views
NumericTextBox
This is a migrated thread and some comments may be shown as answers.
Lee
Top achievements
Rank 1
Lee asked on 28 Mar 2014, 07:18 PM
I am admittedly new to MVC and this may be something very simple that I am missing, but I am at a complete loss as to what else to do other than post here.  I have a model with a basic property called height:

public class BasicInformation
{
        [Display(Description = "Patient's height", Name = "Height (Inches):")]
        [Required(AllowEmptyStrings = false, ErrorMessage = "Height requires a value to be entered.")]
        [Range(12, 96)]
        public double Height { get; set; }
}


I am creating a new basic information and passing to the view when I call the view:
BasicInformation bi = new BasicInformation();
  
return View("Step2", bi);


Now in my view I am binding to this model using:

@(Html.Kendo().NumericTextBoxFor<double>(model => model.Height)
.Name("txtHeight")
.Decimals(0)
.Format("##")
)

My problem is that when I pass the model object to my next method, the value for height has not been updated.  The min & max seems to be working based on the range attribute from the model so it seems as though that part is connected properly.  Also if I use the basic html controls (see below) then it works fine.

@Html.EditorFor(model => model.Height)

Please explain what I am doing wrong or have not set on the Telerik control to have it save the value on the model.

Thanks in advance,
Lee 

4 Answers, 1 is accepted

Sort by
0
Lee
Top achievements
Rank 1
answered on 29 Mar 2014, 01:14 AM
The more I am using the telerik controls I realize I am having the same issue with all of them.  Please help!!!!
0
Daniel
Telerik team
answered on 01 Apr 2014, 01:03 PM
Hello Lee,

The value will not be bound because the input name is overridden with the Name method. You should remove the Name method in this case:
@(Html.Kendo().NumericTextBoxFor<double>(model => model.Height)
    .Decimals(0)
    .Format("##")
)
The correct name will automatically be generated based on the expression when using the NumericTextBoxFor helper. The same problem will occur for the other input widgets if the Name is set a different value than the property name.

Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Michael Taylor
Top achievements
Rank 1
answered on 28 Feb 2020, 04:34 PM

 

Removing the Name property just gives me another error. 

CS1501: No overload for method 'NumericTextBox' takes 1 arguments

Source Error:


Line 20: <p> Line 21: <label for="numeric">Employee Number</label> Line 22: @(Html.Kendo().NumericTextBox<int>(model => model.OrderID) Line 23: .Min(999) Line 24: .Value(1003)

0
Tsvetomir
Telerik team
answered on 03 Mar 2020, 09:07 AM

Hi Michael,

The syntax for creating the NumericTextBox as an editor should actually end with "For". Namely:

@(Html.Kendo().NumericTextBoxFor<double>(model => model.Height)

 

Regards,
Tsvetomir
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
NumericTextBox
Asked by
Lee
Top achievements
Rank 1
Answers by
Lee
Top achievements
Rank 1
Daniel
Telerik team
Michael Taylor
Top achievements
Rank 1
Tsvetomir
Telerik team
Share this question
or