Runtime Scaffolding

In this post i will explain what is Runtime Scaffolding.
Runtime Scaffolding means generating the structure of the view at the runtime based on the models. There are three type of Runtime Scaffolding

  • DisplayForModel    Html.DisplayForModel()       Renders a read-only view of the entire model object
  • EditorForModel      Html.EditorForModel()         Renders editor elements for the entire model object
  • LabelForModel      Html.LabelForModel()           Renders an HTML element referring to the  entire model object

Bellow is the example which explains how you can use Runtime Scaffolding

 Create ProductModel  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Test1.Models
{
public class Product
{
public string Name { get; set; }
public string Category { get; set; }
public decimal Price { get; set; }
}
}
-------------------------------------------------------------------------------------------------------------
Create Controller RuntimeScaffoldingController
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MVC_Grid_Chart.Controllers
{
public class RuntimeScaffoldingController : Controller
{
//
// GET: /RuntimeScaffolding/
public ActionResult RuntimeScaffolding()
{
return View();
}
}
}
-------------------------------------------------------------------------------------------------------------
Create A view
@model Test1.Models.Product
@{
ViewBag.Title = "RuntimeScaffolding";
}

RuntimeScaffolding


@Html.EditorForModel()
----------------------------------------------------------------------------------------------------------
As i have used @Html.EditorForModel() this will desplay the editing option at runtime, In the similar way you can use
Html.DisplayForModel()
Html.LabelForModel()

 Output:

Published by Nirbhay

Technology Geek,Blogger,Reviewer

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: