In a razor-view, how can I check the existence of a property in a model?
if (Model._myProp != null) <--- error .RuntimeBinder.RuntimeBinderException if Model does not contain _myProp
{
...do something
}
In a razor-view, how can I check the existence of a property in a model?
if (Model._myProp != null) <--- error .RuntimeBinder.RuntimeBinderException if Model does not contain _myProp
{
...do something
}
You do not want to check that one of the model's properties has the value null you want to check the type for it is having a property or not and ofcourse you solution will not work that way but @Satpal's wont work too.
Use stronly typed views and separate different properties into interfaces and use them with partial views.