R – ASP.Net MVC run JavaScript in PartialView when loaded using Ajax.ActionLink

ajaxasp.net-mvcpartial-views

I've got a question regarding ASP.Net MVC.

I'm using an Ajax.ActionLink to load a PartialView.

In this partial view is a javascript function I'd like to get called.

However I can't figure out how to make this happen.

I've tried using AjaxOptions { OnSuccess="functionInPartialView" } when I set the Ajax.ActionLink but for some reason it can't see the Javascript.

EDIT: The PartialView is a mix of JavaScript and Html

Best Answer

I would suggest to use jQuery ($.get/$.ajax). It evaluates the $(function(){}) when you load the partial, so your scripts there fire. And I personally find jQuery easier and cleaner to use.