Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
仅在<;中显示字符串Asp.Net webapp的n个字符;p>;要素_Asp.net_Truncate - Fatal编程技术网

仅在<;中显示字符串Asp.Net webapp的n个字符;p>;要素

仅在<;中显示字符串Asp.Net webapp的n个字符;p>;要素,asp.net,truncate,Asp.net,Truncate,我很难将一个字符串切成一定长度,并在其末尾添加“…”。此代码在元素内工作,但在元素内出现错误。我的IDE中没有错误 守则: <p class="card-text"> @{ string x = item.Info.Length > 100 ? item.Info.Substring(0, 100) : item.Info; x = x.Length == 100 ? x + "..." : x; } @Html.Raw(

我很难将一个字符串切成一定长度,并在其末尾添加“…”。此代码在元素内工作,但在元素内出现错误。我的IDE中没有错误 守则:

<p class="card-text">
    @{
        string x = item.Info.Length > 100 ? item.Info.Substring(0, 100) : item.Info;
        x = x.Length == 100 ? x + "..." : x;
    }
    @Html.Raw(x)
</p>

@{ 字符串x=item.Info.Length>100?item.Info.Substring(0100):item.Info; x=x。长度=100?x+“…”:x; } @Html.Raw(x)

错误:

NullReferenceException:对象引用未设置为对象的实例


是否不为空?
item.Info
是否不为空?如果我使用@Html.DisplayFor(modelItem=>item.Info),它会显示文本,但我想截断结果