Rendering Text

To display an XML text element, we have to retrieve the value of the element from the model. Because C# throws an error if it encounters a null value where it expects content, we also have to create logic that tests for a null value.

Depending on the context, there are various ways to render the value of a text element. For example, if our model is an element (@model Ingeniux.Runtime.ICMSElement), the following code will retrieve a Title element.

var title = Model.GetElementValue("Title");

The GetElementValue method automatically performs a null test, so no need to add that logic here. Having stored the value of the title element in the title variable, we can display it between "h3" tags.

<h3 class="title-h3">

Alternatively, we can retrieve the element and then call a partial view to display it.

var title = Model.Element("Title");
    title.ViewMode = "Home";
    Html.RenderPartial("Editable/Title", title);

In this second example, our model is a page (@model Ingeniux.Runtime.ICMSPage) rather than an element. We'll use the ViewMode property to provide display information to the partial view. The partial view will run our null test, check if the ViewMode is "Home" or "Page", and use an HTML helper to display the value of the title in "h2" tags.

var title = Model;
    if (title != null && Model.ViewMode == "Home"
Model.ViewMode == "Page")
<h2 @_Helpers.RenderICEAttribute(Model) 

Here the RenderIceAttribute helper makes the title available for in-context editing.