繁体   English   中英

MVC需要在剃刀视图中混合字符串和C#代码

[英]MVC Need to mix string and c# code in the razor view

我需要证明一下:

显示Model.AgreementsList.Count < Model.Filter.DisplayLastAgreementsCount ? Model.AgreementsList.Count : Model.Filter.DisplayLastAgreementsCount Model.AgreementsList.Count < Model.Filter.DisplayLastAgreementsCount ? Model.AgreementsList.Count : Model.Filter.DisplayLastAgreementsCount @Model.AgreementsList.Count

我需要在cshtml文件中写什么? 我玩了@{} ,但没有找到解决方案。 谢谢

使用@() (使用@{}仅执行随附的代码,不向响应流写入任何内容)

@(Model.AgreementsList.Count < Model.Filter.DisplayLastAgreementsCount ? Model.AgreementsList.Count : Model.Filter.DisplayLastAgreementsCount)

但是,与其在View中执行此类操作相比,您最好制作一个ViewModel甚至使用ViewBag并从Controller分配此输出。

使用@:编写字符串,使用@检索模型中的数据。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM