How to append Ajax.ActionLink using jQuery? -


i'm busy asp.net mvc 3 site. there should view list of links. list populated (or constructed, rather) using jquery.

now, worked saying in javascript function (in seperate javascript file):

$(ul#items).append(<li><a href=...>...</a></li>);

for each item in array.

but change system makes necessary utilize functionality provided ajax.actionlink. if try append <%: ajax.actionlink ... %> above, appends text , not html (i.e. on page displays list of <%: ajax.actionlink... <%>

any suggestions why happening , how make work?

thanks d

isn't following working:

$('ul#items').append('<li><%= ajax.actionlink("hello", "foo", new ajaxoptions {  }) %></li>'); 

of course if using razor view engine:

$('ul#items').append('<li>@ajax.actionlink("hello", "foo", new ajaxoptions {  })</li>'); 

and don't forget in asp.net mvc 3 default jquery used ajax.* helpers might need include jquery.unobtrusive-ajax.js link work.

this being said wouldn't use ajax.* helpers. here's how it:

$('ul#items').append(     $('<li/>', {         html: $('<a/>', {             href: '@url.action("someaction", "somecontroller")',             text: 'hello world',             click: function () {                 $.get(this.href, function (result) {                     alert('ajax success');                 });                 return false;             }         })     }) ); 

update:

i didn't notice stated in separate javascript file. explains it. cannot use server side tags in static file.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -