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
Output:
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 <label> element referring to the entire model object
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";
}
<h2>RuntimeScaffolding</h2>
@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:
No comments:
Post a Comment