截断模型属性在ASP.Net MVC

编程入门 行业动态 更新时间:2024-10-15 20:18:21
本文介绍了截断模型属性在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

本文发布于:2023-11-14 20:19:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1588427.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   模型   ASP   Net   MVC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!