I've tried using this:
Forum.Body = WebUtility.HtmlEncode(Forum.Body);
To encode the a string of text but it still doesn't encode the variable. What's wrong with the syntax?
Razor automatically HTML encodes by default as a security measure.
If you pass a Forum model object to the view and use razor all you will have to do is this:
@Model.Body
In the above it will encode the Body property by default.
This means that you shouldn't have to HTML encode from within the controller.
update
If you intend to output html you can either use:
@Html.Raw(Model.Body)
Or add the following attribute to the property:
[AllowHtml]
public string Body { get; set; }