我们正在使用这个组件www.codeeffects.com,它允许我们根据对象属性创建业务规则。
视图的html是这样的:
@{
ViewBag.Title = "Post Example";
Html.CodeEffects().Styles()
.SetTheme(ThemeType.Gray)
.Render();
}
@using (Html.BeginForm("Evaluate", "Post", FormMethod.Post))
{
<div class="area">
<h1 class="title">Post Example</h1>
<div style="margin-top:10px;">
<span>Info:</span>
<span style="color:Red;">@ViewBag.Message</span>
</div>
<div style="margin-top:10px;">
@{
Html.CodeEffects().RuleEditor()
.Id("ruleEditor")
.SaveAction("Save", "Post")
.DeleteAction("Delete", "Post")
.LoadAction("Load", "Post")
.Mode(RuleType.Execution)
.ContextMenuRules(ViewBag.ContextMenuRules)
.ToolBarRules(ViewBag.ToolBarRules)
.Rule(ViewBag.Rule)
.Render();
}
</div>
</div>
<div class="area">
<h1 class="title" style="margin-top:20px;">Rule Test Form</h1>
@{
Html.RenderPartial("_PatientForm");
}
</div>
}
@{
Html.CodeEffects().Scripts().Render();
}
Run Code Online (Sandbox Code Playgroud)
控制器中的索引操作如下:
[HttpGet]
public ActionResult Index()
{
ViewBag.Rule = RuleModel.Create(typeof(Patient));
return View();
}
Run Code Online (Sandbox Code Playgroud)
Patient 类是这样的:
// External methods …Run Code Online (Sandbox Code Playgroud)