Take the 2-minute tour ×

i have a form in a razor view in my aspnet mvc3 project. The form, submits to a controller action that receives a Custom object that one of the properties is of type HtmlString. That property comes with null from the form submit and if the property is of type string, the value is the one the user writes. How can i get this value when the property is of that type?


Edit: The form is a create post.. what i mean is that is like this:

<form action="@Url.Action("SaveNote", "Application")" method="post" class="note-form" style="display:none">
            <div class="input_item">
                <div class="label">
                    <input type="hidden" name="urlRedirect" value="@Model.UrlRedirect" />
                    <select name="IsPrivate">
                        <option value="False">Public</option>
                        <option value="True">Private</option>
                <div class="input">
                    <textarea name="Body" style="width:290px; height:90px"></textarea>
                <button class="link" type="submit" name="addnote" value="0" >save</button>

The Body is the HtmlString parameter that goes with null to the action.

share|improve this question

3 Answers 3

up vote 1 down vote accepted

HtmlString is simply a wrapper around a normal string to represent already Html encoded strings. So, unless you write a custom binder that creates an HtmlString object through it's constructor HtmlString(string value), you will get a null value for it.

The ToHtmlString() method merely returns the string passed in, atleast in the .NET 4 implementation.

So yes, just use string. It's functionally the same.

share|improve this answer

HtmlString should only be used in custom helpers when rendering some data on the view, but never use a property of this type on your view models. It simply doesn't make sense. Then inside your view based on whether you want to encode or not this string property simply use:



share|improve this answer

Don't use HtmlString. Just use string.

share|improve this answer

Your Answer


