截断模型属性在ASP.Net MVC [英] Truncate model property in ASP.Net MVC

查看:158
本文介绍了截断模型属性在ASP.Net MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即时通讯目前使用不同的方式截断和文本编辑。而且两者都工作正常,但我面临这个问题。我想截断文本编辑里面的文本。 T_T


即时通讯使用截断这种方式及其工作

Im currently using a truncate and texteditor in different way. And both is working fine but I facing this problem. I want to truncate a text inside the texteditor. T_T

Im using truncate this way and its working

@helper Truncate(string input, int length)
    {
    if (input.Length <= length)
    {
        @input
    }
    else
    {
        @input.Substring(0, length)<text>...</text>
    }
}


@foreach (var item in Model)
{       
        <div>
            @Truncate(item.DetailDescription, 400)
        </div>
}






AND

宣布林生叫一个文本编辑这种方式和它也工作正常

@html.Raw(item.DetailDescription)



问题:我怎么可能将二者结合起来在一个单一的功能?这甚至可能T_T

推荐答案

我已经做了这样的人之前。我就是这么做的。

I've done like this one before. I did it this way.

@helper Truncate(string input, int length)
 {
   if (input.Length <= length) {
   @Html.Raw(input)
    } else {
    var thisString = input.Substring(0, length);
    @Html.Raw(thisString)
            }
 }

我结合截断助手里面的原始然后调用截断这样

I combined raw inside the truncate helper then I call the Truncate this way

@Truncate(item.DetailDescription, 400)

这篇关于截断模型属性在ASP.Net MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆