[RESOLVED]Spaces in a string


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?


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

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.


Those quotes aren’t necessary for numeric values

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

Leave a Reply