String

S

shapper

Hello,

I have an Action where I define a ViewData property named Ad:

public ActionResult GoogleAdSense(string client, int height,
string slot, int width) {
StringBuilder ad = new StringBuilder();
ad.AppendLine("<script type='text/javascript'>");
ad.AppendLine("<!--");
ad.AppendLine(String.Concat("google_ad_client = '", client,
"';"));
ad.AppendLine(String.Concat("google_ad_slot = '", slot, "';"));
ad.AppendLine(String.Concat("google_ad_width = ",
width.ToString(), ";"));
ad.AppendLine(String.Concat("google_ad_height = ",
height.ToString(), ";"));
ad.AppendLine("//--> ");
ad.AppendLine("</script>");
ad.AppendLine("<script type='text/javascript' src='http://
pagead2.googlesyndication.com/pagead/show_ads.js'></script>");
ViewData["Ad"] = ad;
return View("GoogleAdSense");
}

Then I use, on the control:

<%= Html.Encode(ViewData["Ad"]) %>

This is not working because I get in my Page Source:

&lt;script type='text/javascript'&gt;
&lt;!--
google_ad_client = '###########';
google_ad_slot = '######';
google_ad_width = 300;
google_ad_height = 250;
//--&gt;
&lt;/script&gt;
&lt;script type='text/javascript' src='http://
pagead2.googlesyndication.com/pagead/show_ads.js'&gt;&lt;/script&gt;

The problem is with the '<' and '>' characters. Any idea why?

One more question: in C# when I want a quote inside a "" should I use
' ?
The generated code shows ' but in Google Ad Sense they say to use ".
I tried to use "" to create a " but I get an error on my code. Why?

Thanks,

Miguel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top