Reputation: 205
I am new to Entity Framework. When I am trying to display using @HTML.DisplayFor. It is displaying extra markup which is resulting as blank in HTML page.
Example: "Test Text" is displayed as <Test> <td> </Text>
Sample Code Looks As Below.
Model
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;}
}
The problem occurred when I tried to display BaseModule in index.chtml
Upvotes: 1
Views: 116
Reputation: 14618
@Html.DisplayFor()
will render a markup template based on the properties type which explains where your unwanted markup is coming from.
From MSDN:
Returns HTML markup for each property in the object that is represented by the Expression expression.
You probably want to use something like @Html.Raw()
Upvotes: 2