How do I get the name, set in the CMS, of a certain block in an MVC view?
I guess that it should be @Model.Name
but I can't find it.
You have to cast your block instance to IContent
to access the Name
property.
For details on why, you can have a look at: Episerver - Why BlockData doesn't implement IContent
The syntax to get the Name property is
(Model as IContent).Name
or
((IContent)Model).Name
Be careful with this cast as handling a Block which is a property as opposed to a ContentReference will not work and throws an exception.
If you want to display the name in the view - you can cast the model inside PropertyFor: @Html.PropertyFor(m => ((IContent)m).Name)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With