in Education by
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)

1 Answer

0 votes
by
Why not simply use HTML pre tag? The pre tag defines preformatted text. Text in a pre element is displayed in a fixed-width font (usually Courier), and it preserves both spaces and line breaks.

Related questions

0 votes
    I want to access Microsoft SQL Server Compact Edition databases from Java. How can I do that? I searched ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 9, 2022 in Education by JackTerrance
0 votes
    I'm coding a basic portfolio page in ASP.NET Core Razor Pages. I want to have a contact form at ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    As you know we can set attributes to actionLink or textBox in razor views but how can we set attributes ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 11, 2022 in Education by JackTerrance
0 votes
    As you know we can set attributes to actionLink or textBox in razor views but how can we set attributes ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 11, 2022 in Education by JackTerrance
0 votes
    What is Razor View Engine in MVC?...
asked Apr 5, 2021 in Education by JackTerrance
0 votes
    I've managed to read some values into a table view and display them in the Master View of a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    In SQL Server Profile, I have it tracing SP:StmtStarting events. The "TextData" includes information like ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 12, 2022 in Education by JackTerrance
0 votes
0 votes
    How Can You Display the Top Five and Bottom Five Sales in the Same View?...
asked Mar 30, 2021 in Technology by JackTerrance
0 votes
    How to display the top five and the last five sales in the same view?...
asked Oct 30, 2020 in Technology by JackTerrance
0 votes
    Looking for a way to drive a Compact Framework app running on a CE device. All we basically need ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 23, 2022 in Education by JackTerrance
0 votes
    I wish to retrieve my the elements inside Users that as a field of ArrayList and display each schedule ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    Create a view named customer mobile details which has the following attributes Display customer istomer name mobile ... ascending order Select the correct answer from above options...
asked Dec 20, 2021 in Education by JackTerrance
0 votes
    I am using C#.Net to send out a HTML email which contains embedded images. These emails work fine ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
...