Ovini
Ovini

Reputation: 351

Issue with displaying spaces in View

I have this code in my MVC3 view. but when I browse this it display only W. Why it doesn't display anything after the space? Is there a better way to display this text using < input> tag?

@var text = "W Z";

<input type=text value=@text >< /input>

Upvotes: 0

Views: 88

Answers (2)

Babak Naffas
Babak Naffas

Reputation: 12581

To build on @MGA's answer, consider that the code you have is translated to

<input type=text value=W Z></input> before being rendered by your browser. The space after the 'W' would then be a terminating delimiter unless you wrap the value in double quotes (value="@text")

Upvotes: 1

Mahmoud Gamal
Mahmoud Gamal

Reputation: 79979

Wrap it with two "" like:

var text = "W z";
<input type="text" value="@text" />

Upvotes: 1

Related Questions