I use this code to generate dynamic controls in MVC.
I am working on MVC Application. The Control names are stored in database like there is 5 rows that contains control name (ex. texbox, dropdown) and I retrieve that data from database on button click using pure MVC.
Now how to retrieve that controls' value in controller.
In model:
public class Controls {
public string ControlName{get;set;}
}
In controller:
public ActionResult Index()
{
List<Controls> _controls=new List<Controls>();//retrieve
data from db in your case
var _c=new Controls();
_controls.Add(new Controls(){ControlName="textbox"});
_controls.Add(new Controls(){ControlName="radio"});
return View(_controls); //
}
In view:
@model List<Controls>
@foreach(var item in Model) {
<input type="@item.ControlName">
}