[英]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.