我在 SQL Server 数据库的文本列中输入了以下 JSon:
{
"tag" : {
"string" : "<input type=\"text\" [attributes] />",
"attributes" : {
"name" : {
"required" : true,
"label" : "Field name",
"description" : "Use only letters and minus sign",
"expert" : false
},
"id" : {
"required" : false,
"label" : "Field identifier",
"description" : "Use only letters and minus sign",
"expert" : true
},
"class" : {
"required" : false,
"default" : "form-control",
"label" : "Field styles",
"description" : "These must exist in the stylesheet, leave blank if you don't know about them",
"expert" : true
},
"required" : {
"required" : false,
"allowed" : [
"required",
""
],
"label" : "Is the field required?",
"description" : "If the user must enter a value in this field, use the word required",
"expert" : true
},
好的,所以基本上这个 JSon 包含输入字段的描述及其所有可能的属性。标签键里面的字符串键,是字段的基本结构。在另一个表中,我基于该结构创建了一个字段,它在 JSon 中有以下信息:
{
"tag" : {
"name" : "username",
"id" : "username",
"class" : "form-control",
"placeholder" : "Enter your name"
}
}
使用 C# 我想将字段呈现为表单:
public string RenderField()
{
var data = JObject.Parse(this.Data); //Data is the field that contains the definition of the field
var structure = JObject.Parse(this.FieldTypes.Datos); // FieldTypes defines the structure of each possible field type
string tagHtml = structure["tag"]["string"].ToString(); // This is the basic form of a form field
foreach(JProperty key in data["tag"])
{
tagHtml = tagHtml.Replace("[attributes]", key.Name + "=\"" + key.Value + "\" [attributes]");
}
return WebUtility.HtmlDecode(tagHtml).Replace("[attributes]", "");
}
基本上一切都按预期工作,但由于某种原因,该字段未显示,但其 htmlentities 如下所示:
<input type="text" name="username" id="username" class="form-control" placeholder="Enter your name" />
我不知道为什么它不解码字符串。有任何想法吗?
拉丁的传说
相关分类