1

I have a query that looks like this:

var ChangesOthersResult = surveyResponseRepository.Query.Select(r => r.ChangesOthers);

That returns all of the entries in "ChangesOthers" column from my table.

When I return the data inside my view:

@Html.DisplayFor(modelItem => modelItem.ChangesOthersResult)

It is returning all of the data as a single continous string of text. How can I add a line break in between the columns of data that it is returning?

  var data = new ResultsViewModel() 
                        {
                            PatientFollowUpResult = PatientFollowUpResult,
                            PatientFollowUpResultPct = PatientFollowUpResultPct,

                            TotalResponsesResult = TotalResponsesResult,

                            ChangesOthersResult = ChangesOthersResult,

                        };

View Model Type

@model CMESurvey.ViewModels.ResultsViewModel
user547794
  • 14,263
  • 36
  • 103
  • 152

3 Answers3

1
<table>
    <tr>
        <th>
            HeaderName1
        </th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
            @Html.DisplayFor(modelItem => modeItem.FieldName)
            </td>
        </tr>
    }
</table>
Kittoes0124
  • 4,930
  • 3
  • 26
  • 47
  • I get an error saying "does not contain a definition for GetEnumerator" if I use a ForEach loop. – user547794 Jun 28 '12 at 21:29
  • @user547794 Then you're not pasting the model to the view AsEnumerable. Can you post the code that passes this to your view? – Kittoes0124 Jun 28 '12 at 21:33
1

Perhaps something like:

@foreach (var x in Model.ChangesOthersResult)
{
   @x<br>
}
orip
  • 73,323
  • 21
  • 116
  • 148
0

Razor doesn't know that you want line breaks in between each item when you use

@Html.DisplayFor(modelItem => modelItem.ChangesOthersResult)

You can literally add the line break in the select by adding the string "<br/>" to each item before selecting it:

var ChangesOthersResult = surveyResponseRepository
                             .Query
                             .Select(r => r.ChangesOthers + "<br />");
JK.
  • 21,477
  • 35
  • 135
  • 214