Q:

Display an integer in a view

I am new to Giraffe and having difficulties displaying an integer. My model is
type Person =
    {
        FirstName   : string
        LastName    : string
        Age         : int
    }

And my view is:
let index2 (model : Person) =
    [
        partial()
        p [] [
            encodedText model.FirstName
            br []
            encodedText model.LastName
            br []
            int model.Age
        ]
    ] |> layout

The error message returned is "All elements of a list must be of the same type. So how do I display the age?

A:

I am not quite familiar with Giraffe (rather Fable), so I do not know what to install and set to reproduce it.
Nevertheless, looking at p [] [ ... ], it is clear that the function requires a list as a second parameter and therefore all the elements there should be of the same type.
Let's look inside. As per GiraffeViewEngine.fs, encodedText returns Text which is a case in XmlNode DU:
type XmlNode =
    | ParentNode  of XmlElement * XmlNode list
    | VoidElement of XmlElement
    | Text        of string

So this sets the type for the whole list, XmlNode.
br function is defined as let br = voidTag "br" where voidTag function returns VoidElement which is another case in XmlNode DU, so it is fine.
And so I do not know what you wanted to say by int model.Age, and int is actually an operator in F# to convert object to integer. Anyways, it does not return anything of type XmlNode. Instead, try
p [] [
    encodedText model.FirstName
    br []
    encodedText model.LastName
    br []
    encodedText (string model.Age)
]

Thereby you will ToString the age, it will turn to Text case of XmlNode and the code should compile.

