【问题标题】:@HTML.DisplayFor is displaying unwanted markup@HTML.DisplayFor 正在显示不需要的标记
【发布时间】:2014-02-17 11:00:12
【问题描述】:

我是实体框架的新手。当我尝试使用@HTML.DisplayFor 显示时。它正在显示额外的标记,导致 HTML 页面中的空白。

示例:“测试文本”显示为<Test> <td> </Text> 示例代码如下所示。

型号

public class ThirdParty
{

    public string ProductId { get; set; }
    public List<string> Options { get; set; }
    public List<string> InputVariables { get; set; }
}

public class ValidationMessage
{

    public string IsRequired { get; set; }
    public List<string> InputVariables { get; set; }
}
  public class LicenseBase
    {
        public string Name { get; set; }
        public string Category { get; set; }
        public List<BaseModule> BaseModules { get; set; }
        public List<ThirdParty> ThirdParty { get; set; }
        public List<string> InputVariables { get; set; }
        public List<ValidationMessage> ValidationMessages { get; set; }
        public List<JPT> JPTProducts { get; set; }
    }
public class BaseModule
{

    public string Category { get; set; }
    public string Name { get; set; }
}

public class Product
{

    public LicenseBase License { get; set; }
    public List<LicenseBase> SubLicenses {get;set;}        

}

当我尝试在 index.chtml 中显示 BaseModule 时出现问题

【问题讨论】:

    标签: c# .net model


    【解决方案1】:

    @Html.DisplayFor() 将根据属性类型呈现一个标记模板,该模板解释了您不需要的标记来自何处。

    来自 MSDN:

    返回由表达式表达式表示的对象中每个属性的 HTML 标记。

    source

    你可能想使用类似@Html.Raw()的东西

    【讨论】:

    • 谢谢!但是,@HTML.Raw() 正在返回类似 . 的东西
    • 我发现了这个问题。我在生成不需要的标记(或被浏览器解释为标记)的函数之前有额外的“
    • 是的,就可以了。如果这有帮助,请考虑accepting it as the answer
    猜你喜欢
    • 1970-01-01
    • 2018-08-08
    • 2012-02-25
    • 2013-06-26
    • 1970-01-01
    • 2019-12-06
    • 2016-09-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多