How do I bind the Kendo Textbox control to its data?

Andy picture Andy · Jun 17, 2015 · Viewed 15.5k times · Source

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" })
)

Answer

Nicholas picture Nicholas · Jun 17, 2015

Use the Kendo().TextBoxFor method:

@(Html.Kendo().TextBoxFor(model => model.FirstName)
    .Name("fName")
    .HtmlAttributes(new { placeholder = "First Name", required = "required", validationmessage="Enter First Name" })
)