REMOVE EXCEED STRING USING JAVASCRIPT IN MVC 4

Jeet Verma

Total Post:110

Points:776
Posted by  Jeet Verma
 1594  View(s)
Ratings:
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!

  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: remove exceed string using JavaScript in MVC 4

    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)

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!