2uzhan.com
Advertisement
Now Place:2uzhan.com » Double quotes inside string variable. e.g " my name is "jaikit" and what is "

Double quotes inside string variable. e.g " my name is "jaikit" and what is "

Web Development @ June 29, 2009   Views:0

Hello Doc's,

I am using asp.net MVC for my application.

I am dynamically generating HTML content from my controller using STRING variable. Below mentioned is the code snippet generaed by my controller using c#

<ul id=\"dhtmlgoodies_tree2\" class=\"dhtmlgoodies_tree\"><li id=\"1\" > <%=Ajax.ActionLink(\"ATI Display Driver\", \"Test/5\",new AjaxOptions(){UpdateTargetId=\"returnData\"}) %>

Now when above code reaches my VIEW, my scriplet ( <% %>) tag consists of literal ' \ ' which is not executed. Literals in pure HTML code have no problem.

When I hardcoded above snippet inside my view it executes perfectly which has no literal ' \ ' .

<ul id=\"dhtmlgoodies_tree2\" class=\"dhtmlgoodies_tree\"><li id=\"1\" > <%=Ajax.ActionLink("ATI Display Driver", "Test/5",new AjaxOptions(){UpdateTargetId="returnData"}) %>

After generating string inside controller I tried to replace literal but it gives me RUN TIME error. Because doublequotes ( " ) without literal (' \ ' ) is not permitted.

I would really appreciate If some one could suggest me way to generate the HTML.

Thank You

Jaikit Savla

--------------Solutions-------------

If you embed a quote in a string you need to escape it or use "", I think you are asking how to get a string representation of the HTML?

string s = @"<ul id=""dhtmlgoodies_tree2"" class=""dhtmlgoodies_tree""><li id=""1"" > <%=Ajax.ActionLink(""ATI Display Driver"", ""Test/5"",new AjaxOptions(){UpdateTargetId=""returnData""}) %>";

The <% %> will not evaluate properly so you will want to add that in code. I hope I understood your question properly.

Hello Snake,

The snippet which you menioned will work fine. But I am dynamically building the string like this:

rss += "<li id=\"" + m.DependentAppID + "\" noRename=\"true\"><%=Ajax.ActionLink(\"" + m.DependentAppID + "\", \"Test\\5\",new AjaxOptions(){UpdateTargetId=\"returnData\"}) %> ";

Please let me know how should I do this

Hello,

I tried to rewrite the code like this:

rss += @"<li id="" " + m.DependentAppID ;
rss += @" ""  noRename= ""true ""><%=Ajax.ActionLink("" "+ m.DependentAppID;
rss += @" "" , ""Test\5"" , new AjaxOptions(){UpdateTargetId=""returnData""}) %>";

But still I was not able see the html in browser. The reason being when I checked the rss string it still generated literal ' \ ' . And Ajax.ActionLink doesnot executes litereal

When a user enters the page in question, a textarea is populated from data from a text file stored on the server. The user can then edit that text (add, ...

I'm attempting to simplify my fundraising page, and would like to show exactly how much each donation would help us out. I've listed the options below, but I would like ...

I have a list.php which displays all the records that is in the database with 2 options Edit or Delete. When clicked its suppose to delete by id but instead ...

Tags:asp.net
© 2018 2uzhan.com Contact