0

I have a Description field that brings back a large amount of text. When it writes to the page it comes out as one big line. I have tried wrapping it in the below two divs

         <td>
            <div style="word-wrap:break-word;">
                @Html.DisplayFor(modelItem => item.Description)
            </div>
        </td>

and

         <td>
            <div style="overflow:auto;">
                @Html.DisplayFor(modelItem => item.Description)
            </div>
        </td>

The strange thing is they both seem to work for a second when the screen first loads and then it goes back to one line.

I have looked online and ever answer I find says the above should work.

Is anyone aware of something I am missing?

Any help would be greatly appreciated.

MintBerryCRUNCH
  • 530
  • 4
  • 21
  • The following post may present one or more solutions to your problem: https://stackoverflow.com/questions/9030763/how-to-make-html-displayfor-display-line-breaks/17273367 – David Tansey Oct 09 '20 at 16:14
  • Does this answer your question? [Word-wrap in an HTML table](https://stackoverflow.com/questions/1258416/word-wrap-in-an-html-table) – GSerg Oct 10 '20 at 09:54
  • This has nothing to do with ASP.NET and everything to do with HTML and CSS. – GSerg Oct 10 '20 at 09:55
  • Does this answer your question? [How to force table cell content to wrap?](https://stackoverflow.com/q/6666532/11683) – GSerg Oct 10 '20 at 09:57

1 Answers1

-1

The links in the comments helped but in the end I had to do a count through the data to add in the br every hundred characters. Then if there where no spaces by the 15th loop it would add one in any way.

 public static MvcHtmlString Display100<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression)
    {
        var metadata = ModelMetadata.FromLambdaExpression(expression, html.ViewData);
        var model = html.Encode(metadata.Model);
                                                  
        if (String.IsNullOrEmpty(model))
        return MvcHtmlString.Empty;

        if (model.Length > 100)             
        for (int i = 100; i <= model.Length; i++)
        {
                if (model.Length - i > 0)
                {         
                    
                    if (Char.ToString(model[i]) == " ")
                    {
                        model = model.Insert(i, "<br />");
                        i += 100;
                        i = i.Round(100);
                    }
                    if(((double)i/100) % 1 > 0.15)
                    {
                        model = model.Insert(i, "<br />");
                        i += 100;
                        i = i.Round(100);
                    }
                }
        }
MintBerryCRUNCH
  • 530
  • 4
  • 21