I've a following model propertyies one of which is projectDescription that generates an ntext
column in SQL Server.
Model:
--some other properties here....
[Display(Name = "Project Title")]
[Column(TypeName = "varchar(125)")]
public string ProjectTitle { get; set; }
[Column(TypeName = "ntext")]
public string ProjectDesctiption { get; set; }
--some other properties here....
This property is bound to a textarea
tag in a View
as follows. But instead of displaying the real data from the ProjectDesctiption
column from the Db it oddly displays the entire html source page of the View the page - as shown in image below. Other tags correctly display the data as shown in ProjectTitle field in the same image below. I think the issue is related to ntext datatype and the ASP Tag helper for textarea. I did check in the database that the max length of some data cell in the ProjectDescription is quite big - about 61968 characters. But we do want to display the data from this column with a reasonable textarea length and width with horizontal and vertical scrollbars so user can at least glance through the data of this field to get an idea of what the project description is (for example) or may be copy/past the data from the textrea for some purpose. Question: How can I achieve this goal?
View:
---some html here.....
<div class="form-group">
<label asp-for="ProjectTitle" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="ProjectTitle" class="form-control" />
<span asp-validation-for="ProjectTitle" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<label asp-for="ProjectDesctiption" class="col-md-2 control-label"></label>
<div class="col-md-10">
<textarea asp-for="ProjectDesctiption" class="form-control" rows="6" cols="15" />
<span asp-validation-for="ProjectDesctiption" class="text-danger"></span>
</div>
</div>
...some other html here...
A <textarea>
is not a self closing tag and because you have not 'closed' it, its displaying the html that follows the tag.
Change you code to
<textarea asp-for="ProjectDesctiption" class="form-control" rows="6" cols="15"></textarea>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments