How to

29 Mar 20181 minute to read

Render TileView from Code behind

TileView 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 TileView properties in the controller.

  • C#
  • //Namespace to get the JavaScript (TileView) component properties
    using Syncfusion.JavaScript.Models;
    
    namespace MvcApplication.Controllers
    {
        public class TileController: Controller
        {
            public ActionResult TileFeatures()
            {
    
                 //Initializing the TileView model
    
                TileProperties tileObj = new TileProperties();
    
                //Initializing the other properties
    
                tileObj.TileSize = Syncfusion.JavaScript.TileSize.Medium;
                tileObj.ImageUrl = "http://js.syncfusion.com/ug/web/content/tile/alerts.png";
                tileObj.Text = "Alerts";
    
                //Passing TileView properties using the ViewData
    
                 ViewData["TileModel"] = tileObj;
    
                return View();
            }
        }
    }

    Binding the TileView properties passed via ViewData from the controller in the client side as below.

  • CSHTML
  • @{
        Html.EJ().Tile("Tile1", (Syncfusion.JavaScript.Models.TileProperties)ViewData["TileModel"]).Render();
    }