yad4u AJAX with Jquery in ASP.MVC2

AJAX with Jquery in ASP.MVC2

I'd like to get something via Ajax and put it into

What i have to return from Controler Action to put this into that DIV? Right now i had standard ASP.MVC view as result...

public ActrionResult MyAction() {    return View(); } 

and in javascript i have:

$.get(<url to controler action>, null, function(data) { $(#result).html(data); }) 

Typical action associated with MyAction, with reload page works perfect. but when i do $.get(...) i got whole page in "data" (content and master page). How can i get only part of View(), without MsterPage??

Returning JSON data to view page in ASP.NET MVC


Adding Include Files to the Add Controller T4 Templates in ASP.NET MVC
You could return a partial:.
is there a way to programatically set a filter in jquery jqgrid?
public ActrionResult MyAction()  {    return PartialView(); } 
Where you have MyAction.ascx partial containing some HTML fragment:.
Asp.net MVC utilising WCF
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %> <div>Hello</div> 
And you inject this partial using an AJAX call into the #result div:.
Which strategy to choose for building web based business application

ASP.NET MVC output cache with dynamic fragment

Redirect site from www.a.com to a.com in asp.net mvc


Jquery thickbox to work with Url.Action link in Asp.net mvc
You'll want to use .
public ActrionResult MyAction() {     var stuff = new { id = 1, name = "test" }; //or whatever stuff you need in your page     return Json(stuff); } 
from your ActionResult method.



As an alternative to a json response, you can return the html.

All you need to do is to filter and get the html that you want to append from the 'data' variable..
$.get(<url to controler action>, null, function(data) {                $('#result').html($(data).find('#partOfViewID').html());                }); 


that's not a problem with jquery / ajax.

you need an action that returns a partial view.

not one that returns a view with a master page.

. you can use this part:.
$.get(, null, function(data) { $(#result).html(data); }).
but your action will have to have a partial view associated with it, not a regular view with a master page.. so make a new action.

add a view to it, check the partial view checkbox.

and put whatever you want to be reloaded in that partial view.


76 out of 100 based on 76 user ratings 226 reviews