How to?
4 Apr 20181 minute to read
Render Checkbox from Code behind
Checkbox can be rendered from the code behind by initializing the required properties in controller and passing those properties via ViewData or Model to the client side.
The following code illustrates the initialization of Checkbox properties in the controller.
//Namespace to get the JavaScript (Checkbox) component properties
using Syncfusion.JavaScript.Models;
namespace MvcApplication.Controllers
{
public class CheckboxController : Controller
{
// GET: Checkbox
public ActionResult CheckboxFeatures()
{
//Initializing the Checkbox model
CheckBoxProperties BtnObj = new CheckBoxProperties();
//Initializing the datasource and other properties
BtnObj.Checked = true;
BtnObj.Text = "Checkbox";
BtnObj.ShowRoundedCorner = true;
//Passing Checkbox properties using the ViewData
ViewData["BtnModel"] = BtnObj;
return View();
}
}
}
Binding the Checkbox properties passed via ViewData from the controller in the client side as below.
@{
Html.EJ().CheckBox("searchCustomer",(Syncfusion.JavaScript.Models.CheckBoxProperties)ViewData["BtnModel"]).Render();
}