mvc5 if html,Razor CSHTML IF statement

这段代码演示了如何从 Umbraco 网站获取可见的 Article、sergrein 或 solomyndagrein 类型的节点,并按创建日期降序排列,显示前10个的创建日期和标题。需求是如果文章标题超过10个字符,则显示前10个字符后加省略号,不足10个字符则显示全标题。
摘要由CSDN通过智能技术生成

Anyone here that can help me? I have the following code:

@inherits umbraco.MacroEngines.DynamicNodeContext

@{

var node = @Model.NodeById(1257);

}

Newest

@foreach (var article in node.Descendants().Where("Visible && (NodeTypeAlias = \"Article\" || NodeTypeAlias = \"sergrein\" || NodeTypeAlias = \"solomyndagrein\")").OrderBy("createDate desc").Take(10))

{

@article.createDate.ToString("dd/MM") | @article.title

}

What I want is: if @article.title is longer than e.g. 10 characters, it needs to return the 10 characters followed by ... (for example: "this_is_a_..."). If the @article.title is shorter than 10 characters, it can just show the full title length.

How can this truncating be done?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值