简体   繁体   English

如何检查Razor模板中的模型中的属性是否可用?

[英]How to check if a property is available in the Model in Razor Template?

I want to check in a razor template if a certain property is available in the Model. 我想检查一个剃刀模板,如果模型中有某个属性可用。

Can you please tell me how I can do that?, I am using the below code: 您能告诉我该怎么做吗?,我正在使用以下代码:

if (Model.objectIds !=null)

When I am doing this I am getting an exception: 当我这样做时,我得到一个例外:

"'RazorEngine.Compilation.RazorDynamicObject' does not contain a definition for 'objectIds'"

您可以在剃刀视图中尝试以下操作:

if (Model.GetType().GetProperty("objectIds") != null)

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

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