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

7 Years
Discussion Span
Last Post by jktsavla

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.