Quantcast
Channel: User mykhailovskyi - Stack Overflow
Viewing all articles
Browse latest Browse all 29

Answer by mykhailovskyi for How to add condition to output in MVC?

$
0
0
@(string.Format("{0}", Model.Toxin[i].intake_link[0].Length > 30 ?Model.Toxin[i].intake_link[0].Substring(0, 30) : Model.Toxin[i].intake_link[0])

But I suggest you write some string extension and use it:

public static string TrimToMaxLength(this string value, int maxLength)
{
    return (value == null || value.Length <= maxLength ? value : value.Substring(0, maxLength));
}

and then use anywhere:

Model.Toxin[i].intake_link[0].TrimToMaxLength(30)

Viewing all articles
Browse latest Browse all 29

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>