Dylan Slabbinck Dylan Slabbinck - 2 years ago 230
HTML Question

Jquery .append() & Html.Helper

Is there any way to put html.helper inside a .append() function.

success: function (html) { $("#Resultaatsgebied").append(' <li>@Html.TextBoxFor(item => Model.RG1)<ul id="Concretisering" class="subList"><li>@Html.TextBoxFor(item => Model.RG1sub1)</li></ul>@Html.ActionLink("+", "index", null, new { id = "addConcretisering" })</li>'); }

This works, but just as a string, not as a control


This works now, but the actionlink who is generated does not.
I have the same actionlink default in my view, and there it works.
But for the generated one, I think he just does not execute the ajax call?

Answer Source

If your code is in a razor view, you can put into brackets your razor code like this :

success: function (html) { 
    $("#Resultaatsgebied").append(' <li>@(Html.TextBoxFor(item => Model.RG1))<ul id="Concretisering" class="subList"><li>@(Html.TextBoxFor(item => Model.RG1sub1))</li></ul>@(Html.ActionLink("+", "index", null, new { id = "addConcretisering" }))</li>'); 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download