8

I have designed a view using some of the Kendo Telerik controls. I am not sure how to bind their controls to data.

This generated scaffolded method works :

@Html.EditorFor(model => model.surName, new { htmlAttributes = new { @class = "form-control" } })

How do I bind the Kendo Textbox?

@(Html.Kendo().TextBox()
    .Name("fName") 
    .HtmlAttributes(new { placeholder = "First Name", required = "required", validationmessage="Enter First Name" })
)
Nic
  • 12,220
  • 20
  • 77
  • 105
Andy
  • 299
  • 1
  • 2
  • 13

1 Answers1

13

Use the Kendo().TextBoxFor method:

@(Html.Kendo().TextBoxFor(model => model.FirstName)
    .Name("fName")
    .HtmlAttributes(new { placeholder = "First Name", required = "required", validationmessage="Enter First Name" })
)
Nic
  • 12,220
  • 20
  • 77
  • 105
  • Thanks, I get an error when adding the .Value(Model.surName) Object reference not set to an instance of an object? The TextBoxFor was accepted but does not bind without the .value? – Andy Jun 17 '15 at 06:41
  • Looks like your model is `null`? `surName` can be empty I think. I don't think you need to use `.Value(Model.surName)`. Note that I used `TextBoxFor` – Nic Jun 17 '15 at 06:51
  • Was looking around and saw this. Looks like your field names are mixed. The field **surName** is not the same field as **fName**. The fact Kendo is used should not affect what happens, only how it is rendered. – Taersious Dec 07 '18 at 16:42