5

I am very new to MVC and razor, but I am enjoying it so far. There are one or two basics I am having trouble with so hopefully this will be a nice easy one for someone.

I am making a new variable and replacing the white spaces. However, this doesn't appear to be working at all; the space that I am adding to the string myself remains. I cannot simply use the underscore at this point as both Address1 and Postcode may also contain spaces, so the replace is essential.

@{ 
    var mapAddress = Model.Address1 + ", " + Model.Postcode;
    mapAddress.Replace(" ", "_");
}
1

1 Answer 1

11

You must use the return value of pure method Replace, that is:

mapAddress = mapAddress.Replace(" ", "_");
Sign up to request clarification or add additional context in comments.

2 Comments

I'm actually ashamed to have failed so hard! Sometimes the most obvious things pass me by. Thanks!
I'd say most people have made this mistake at some stage. Sometimes a unit test of even the most simple bits of code helps you understand and remember what the code better.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.