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

Recommended Answers

All 3 Replies

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


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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.