views:

288

answers:

6

I'm building a Ajax.ActionLink in C# which starts:

<%= Ajax.ActionLink("f lastname", ...more stuff

and I'd like there to be a new line character between the words "f" and "lastname". How can I accomplish this? I thought the special character was \n but that doesn't work, and <br> doesn't work either.

A: 

Try this:

<%= Ajax.ActionLink("f<br />lastname", ...more stuff
Andrew Hare
A: 

You can't use <br /> because the ActionLink method (and indeed I believe all the html and ajax extension methods) encode the string. Thus, the output would be something like

<a href="...">f&lt;br /&gt;lastname</a>

What you could try instead would be a formatting:

<%= string.Format(Ajax.ActionLink("f{0}lastname", ...more stuff), "<br />") %>
Joel Potter
Darn doesn't work. That gets me a--"System.Web.HttpCompileException was unhandled by user codeerror CS1010: Newline in constant"
Whozumommy
Hmm, trying using .Replace instead of string.format? I haven't really worked with ajax extensions, so I don't know of another way to do this.
Joel Potter
A: 

The \n used to work for me. But now it seems to be depricated. Alternitavely, you may use the NewLine method, for example:

string jay = "This is a" + Environment.NewLine + "multiline" + Environment.NewLine + "statement";

baeltazor
A: 

Did you try the \r\n combination?

Grinn
A: 

You might have to revert to doing something like:

<a href="<%= Url.Action("action") %>">f<br />last</a>

And then wire in the Ajax bits manually.

Wyatt Barnett
A: 

How about:

<%= Server.UrlDecode(Ajax.ActionLink(Server.UrlEncode("f<br/>lastname"), ...more stuff
Grinn