I'm in need of some help in getting a View to layout data it is accessing from a database correctly.
I have a simple View on my MVC3 c# site to display the data stored in a database. The View code is below:
@foreach (var item in Model)
{
@Html.DisplayFor(modelItem => item.News_Date)
@Html.DisplayFor(modelItem => item.News_Entry)
}
This works fine initially, the data is displayed as shown below:
Date
Post
Date
Post
Date
Post
...etc
The issue I have now is that when viewing the "Post" data using the method above it doesn't include carriage returns, so paragraphs etc are not displayed correctly with line breaks.
I received some help earlier from people on this site on how to achieve a bit of formatting when displaying typing data into a TextArea box and uploading it to a database, then displaying that data (including line breaks) on a separate page View. The method they gave me to display this data is below:
@foreach (var data in Model)
{
@Html.Raw(data.News_Entry.Replace(Environment.NewLine, "
"))
}
This preserved line-breaks that were used in the original data input.
However, now if I want to display data I have to use this method to display the "date":
@foreach (var item in Model)
{
@Html.DisplayFor(modelItem => item.News_Date)
}
...and this method to display the "post":
@foreach (var data in Model)
{
@Html.Raw(data.News_Entry.Replace(Environment.NewLine, "
"))
}
...but it doesn't display the data on the page like before, i.e:
Date
Post
It displays it as:
Date
Date
Date
Post
Post
Post
Would anyone please be able to help me get around this?
Preferably, I'd like to have the Date displayed first, and the post displayed underneath it, whilst keeping linebreaks intact.
To maybe illustrate a bit better, I have a couple of screenshots:
Correct way to display
Incorrect way to display
Many thanks.
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)