Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 316
sf. Avatar asked Dec 03 '09 15:12

sf.


People also ask

Where do you put Javascript on a razor page?

A JS file for the Index component is placed in the Pages folder ( Pages/Index. razor. js ) next to the Index component ( Pages/Index. razor ).

How load partial views in ASP NET MVC using jquery Ajax?

The GetPartial() action create a List of countries. It then calls the PartialView() method to return the partial view to the client. The first parameter of PartialView() is the name of the partial view and the second parameter is the model object to be passed to the partial view.

How can I return a partial call from Ajax?

When making AJAX requests, it is very simple to return HTML content as the result. Simply return an ActionResult using the PartialView method that will return rendered HTML to the calling JavaScript. Now define an action method in the book controller that returns an ActionResult using the PartialView.


1 Answers

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.

like image 149
queen3 Avatar answered Nov 15 '22 02:11

queen3