как я могу подстроку в MVC. В чем моя вина здесь? - PullRequest
0 голосов
/ 19 марта 2019

Как я могу использовать Substring в MVC?

@if (i.Aciklama.Length > 50)
{                                          
    @Html.Raw(i.Aciklama.Substring(0,50))...
}
else
{
    @Html.Raw(i.Aciklama)
}

1 Ответ

0 голосов
/ 20 марта 2019

Я предполагаю, что Aciklama имеет строковый тип

@Html.DisplayFor(model => model.Aciklama).ToString().Substring(0,50)

или использует расширения

namespace YourApp.Extensions
{
  public static class StringExtensions 
  {
    public static string Truncate(this string input, int max)
    {
      if(!String.IsNullOrEmpty(input) && input.Length > max)
      {
         return input.Substring(0,max);
      }
    }
  }
}

По вашему мнению добавьте с помощью YourApp.Extensions;

@Model.Aciklama.Truncate(50)
...