C# 实体字符串未在C中解码#

C# 实体字符串未在C中解码#,c#,json,asp.net-mvc,decode,C#,Json,Asp.net Mvc,Decode,我在SQL Server数据库的文本列中输入了以下JSon: { "tag" : { "string" : "<input type=\"text\" [attributes] />", "attributes" : { "name" : { "required" : true, "label" : "Field name", "description" : "Use only letters and minus sign", "exp

我在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
   },
   "pattern" : {
    "required" : false,
    "label" : "Input pattern that must be followed",
    "description" : "This is a regular expression that will validate the field's value",
    "expert" : true
   },
   "autocomplete" : {
    "required" : false,
    "default" : "off",
    "allowed" : [
     "on",
     "off",
     ""
    ],
    "label" : "Allow autocomplete?",
    "description" : "If you wish the browser's built in autocomplete to remember the answer, set this on",
    "expert" : true
   },
   "placeholder" : {
    "required" : false,
    "label" : "Hint for the user",
    "description" : "Write an example value that can be entered in this field",
    "expert" : false
   }
  }
 }
}
使用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]", "");
    }
基本上一切正常,但由于某些原因,该字段未显示,但其HTMLEntity如下所示:

&lt;input type=&quot;text&quot; name=&quot;username&quot; id=&quot;username&quot; class=&quot;form-control&quot; placeholder=&quot;Enter your name&quot;  /&gt;

我不知道为什么它没有解码字符串。有什么想法吗?

您试图显示html,问题不在于方法,而在于您没有在mvc中正确打印它。照建议的那样做:


你是对的,以前有人评论过相同的解决方案,我在我的观点中尝试过。它解决了这个问题。
&lt;input type=&quot;text&quot; name=&quot;username&quot; id=&quot;username&quot; class=&quot;form-control&quot; placeholder=&quot;Enter your name&quot;  /&gt;
@Html.Raw(RenderField())