[RESOLVED]Spaces in a string

Hello.

Below is a simple example to illustrate the problem I’m having when a string is used in a hidden field.

The source code shows the value ends with the space in "Vice President". Why, and how do I get around this issue?

Thanks.

@{
     string position = "Director,President,Vice President,Secretary,Treasurer";
 
     if(IsPost)
            {
                position = Request["position"];
                <p>Position: @position</p>
            }
}
 
<!DOCTYPE html>
<html lang="en">
    <body>
        <form method="post">
        <p>@position</p>
        <input type="hidden" name="position" value= @position />
        <p><input class="green" type="submit" name="buttonSubmit" value="Submit" /></p>
        </form>
    </body>
</html>

You need some quotes:

<input type="hidden" name="position" value="@position"  />

Ah yes, makes sense for strings. Those quotes aren’t necessary for numeric values and that is what I copied from.

Lesson learned.

Thx Mike.

jw7965

Those quotes aren’t necessary for numeric values

A rare backward step introduced by HTML5. However, I always quote attribute values.

Leave a Reply