Home > DeveloperSection > Forums > remove exceed string using JavaScript in MVC 4
Jeet Verma
Jeet Verma

Total Post:110

Points:776
Posted on    February-14-2013 1:49 AM

 ASP.NET MVC ASP.NET MVC 
Ratings:


 1 Reply(s)
 1137  View(s)
Rate this:

Hi Expert!

I'm working on MVC project. I have bind string into MVC control through property. I want to display exceed string as below

"Model View Control Demo..."

My code as below

@Html.DisplayFor(modelItem => item.Description)

Please reply ASAP!

Thanks in advance!



AVADHESH PATEL

Total Post:604

Points:4228
Posted on    February-16-2013 3:51 AM

Hi Jeet!

Create helper method for remove exceede string from fixed lenght

@helper Truncate(string input, int length)
        {
            if (input.Length <= length)
            {
        @input
            }
            else
            {
        @input.Substring(0, length)<text>...</text>
            }
    }

Use this method in place of your MVC control

@Truncate(item.Description, 30)


Don't want to miss updates? Please click the below button!

Follow MindStick