ASP.NET MVC İle Cshtml Dosyasında Helper Oluşturma Ve Kullanma
İlk örneğimizde Kisalt adındaki metodumuza geçeceğimiz iki parametre ile string değerin ne kadarlık kısmının gösterileceğiniz ayarlayabiliyor olacağız eğer belirttiğimiz uzunluk değerinden büyük ise kisaltip sonuna 3 nokta ekleyecektir değil ise olduğu gibi geri yazdıracaktır.
1 | @helper Kisalt(string text, int length){ |
2 | @String.Format("{0}{1}", text.Substring(0, text.Length > length ? length : text.Length), text.Length > length ? "..." : ""); |
3 | } |
4 | <div> |
5 | @Kisalt("Tincidunt integer eu augue augue nunc elit dolor, luctus placerat scelerisque euismod, iaculis eu lacus nunc mi elit, vehicula ut laoreet ac, aliquam sit amet justo nunc tempor, metus vel.", 50) |
6 | </div> |
Hiç yorum yok:
Yorum Gönder