ajax - Building HTML and appending using jQuery -


i'm stuck scenario such following:

$(document).ready(function () {         var param1 = "a";         var param2 = "b";         var param3 = "c";         $("ul#someul").append('<li><%: ajax.actionlink("click me", "someaction",  new { param1 = "' + param1 + '", param2 = "' + param2 + '", param3 = "' + param3 + '" }, new ajaxoptions() { onsuccess = "onsuccess" }, new { class = "abc" } ) %></li>'); 

now problem instead of value of each of param# variables being "inserted"...the variable name (e.g. param1) gets "inserted"...in other words routevalues being posted controller action param1, param2, , param3 instead of a, b, , c...does know why happening , how fix it?

thanks d

actionlinks useless in case server side code. cannot mix them client side javascript variables. here's how (embracing full power of jquery):

$(function () {     var param1 = 'a';     var param2 = 'b';     var param3 = 'c';     $('ul#someul').append(         $('<li/>', {             html: $('<a/>', {                 href: '<%= url.action("someaction") %>',                 text: 'click me',                 class: 'abc',                 click: function() {                     var params = {                          param1: param1,                          param2: param2,                          param3: param3                      };                     $.get(this.href, params, function(result) {                         onsuccess();                     });                     return false;                 }             })         })     ); }); 

Comments