1

I am using MVC5. I am loading images from a list using Unobtrusive Ajax.ActionLink(). Here is the sample code:-

<ul class="list-group list-unstyled lists">
@foreach (var item in Model)
{
<li>
@Ajax.ActionLink(@item.Name,
        @item.Action,
        "Home",
        new {id = @item.Id },
        new AjaxOptions
        {
            UpdateTargetId = "divImage",
            InsertionMode = InsertionMode.Replace,
            HttpMethod = "GET",
            OnSuccess = "enableZoom"
        })
</li>
}
</ul>

OnSuccess callback I call a function 'enableZoom'. It works as long as it is within the script tag of the view page. But When I move enableZoom function to custom.js file, OnSuccess callback can't find or call it.

<script>
    function enableZoom() {
        $("#divImage").zoom({
            on: "grab",
            magnify: "1"
        });
    }
</script>

PS: My custom.js file is loading successfully (confirmed through firebug) and custom.js has other functionality too and that is working. Any clue/help would be appreciated?

user1327064
  • 4,187
  • 5
  • 20
  • 30

1 Answers1

0

Try to use the following in the seperate js file. Since you are using Jquery functions, you want to be sure that Jquery is loaded before your Js file.

MyNamespace = {} || MyNamespace();
MyNamespace.EnableZoom = function() {
    $("#divImage").zoom({
            on: "grab",
            magnify: "1"
        });
};

You should be able to call this function by MyNamespace.EnableZoom()

OnSuccess = "MyNamespace.EnableZoom"

Give it a try. Good luck.

Hasan Savran
  • 367
  • 2
  • 5