tags:

views:

97

answers:

2

Suppose I have an action that returns an rendered asp.net mvc control and send it as a response for AJAX request.

I want to have the response of that action during the whole page is rendering in a view.

public class Controller
{
  ....

  public ActionResult AjaxAction(string parameter)
  {
    return PartialView("~/Views/Controls/Control.ascx",parameter);
  }
}

now in view that renders the whole page I want something like:

<%var par = "1";%>
<%= AjaxAction(par) %>
A: 

I would use the jQuery load function, fired when the document is ready, and load the partial view into a div.

$(function() {
   $('#partialResult').load( '<%= Url.Action( "AjaxAction", "Controller", new { parameter = "1" } ) %>' );
}

 <div id="partialResult">
 </div>
tvanfosson
+1  A: 

Depending on what you want to achieve partial requests may work for you. This is typically useful where your control is some form of 'widget'.

thatismatt
Thanks for pointing me there. Really helpful.
Jenea