如何在MVC中使用子字符串?
@if (i.Aciklama.Length > 50)
{
@Html.Raw(i.Aciklama.Substring(0,50))...
}
else
{
@Html.Raw(i.Aciklama)
}
答案 0 :(得分:0)
我猜Aciklama是字符串类型
Record1 = [{"ID":"938"},{"ID":"939"}];
Record2 = [{"IDN":"938"},{"IDN":"939"}];
const IDNs = new Set(Record2.map(({ IDN }) => IDN));
const Record1WithoutDupes = Record1.filter(({ ID }) => !IDNs.has(ID));
console.log(Record1WithoutDupes);
或使用扩展名
@Html.DisplayFor(model => model.Aciklama).ToString().Substring(0,50)
在您的视图中使用YourApp.Extensions添加;
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);
}
}
}
}