Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wrap the text in the DisplayFor in MVC view?

comments extends I am developing a MVC app. I have a commenting feature in the app.

My problem is, when any user posts a comments without pressing the enter key, then the comment comes out as one single line and crosses the screen and the user has to scroll horizontally to see the entire comment.

I want to wrap the comment and show it at a specific width.

Ex.

admin 04 May 13 12:43 PM zxczxcasdasdzxczxcasdasdzxczxcasdasdzxczxcasdasdzxczxcasdasdzxczxcasdasdzxczxcasdasdzxczxca

I use the below code to show the comments in the view

<div class="CommentP" style="width:550px;" >
 @Html.DisplayFor(ModelItem => item.CommentText, new {style = "width:550px;" })
</div>
like image 467
bnil Avatar asked Oct 22 '25 18:10

bnil


1 Answers

Use <div style="word-wrap:break-word;"> or <div style="overflow:auto;">

like image 100
rickythefox Avatar answered Oct 24 '25 07:10

rickythefox