پیاده سازی Template تو در تو در AngularJS و ASP.NET MVC
نویسنده: میثم نوایی
تاریخ: ۱۳۹۳/۰۷/۱۹ ۱۵:۵۵
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
public class Form
{
public string Name { get; set; }
public string Title { get; set; }
public List<BaseElement> Elements { get; set; }
}
public abstract class BaseElement
{
public string Name { get; set; }
public string Title { get; set; }
}
public class Section : BaseElement
{
public List<TextBox> Elements { get; set; }
}
public class TextBox : BaseElement
{
public string Value { get; set; }
public string CssClass { get; set; }
} public class FormBuilderController : Controller
{
//
// GET: /FormBuilder/
public ActionResult Index()
{
var form = new Form();
var section = new Section() { Title = "Basic Info", Name = "section01" };
section.Elements.Add(new TextBox() { Name = "txt1", Title = "First Text Box" });
form.Elements.Add(new TextBox() { Name = "txt1", Title = "Second Text Box" });
var formJson=JsonConvert.SerializeObject(form);
return View(formJson);
}
} <script type="text/ng-template" id="ElementTemplate">
<div ng-if="control.Type == 'JbSection'">
<h2>{{control.Title}}</h2>
<ul>
<li ng-repeat="control in control.Elements" ng-include="'ElementTemplate'"></li>
</ul>
</div>
</script> <script type="text/ng-template" id="element.html">
{{data.label}}
<ul>
<li ng-repeat="element in data.elements" ng-include="'element.html'"></li>
</ul>
</script>
<ul ng-controller="NestedFormCtrl">
<li ng-repeat="field in formData" ng-include="'element.html'"></li>
</ul>