Show an action that returns a partial view in a view

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

I want the response of this action to be displayed in the view during the whole page.

public class Controller
{
  ....

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

      

now, which does the whole page, I want something like:

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

      

+1


a source to share


2 answers


Depending on what you want to achieve, partial queries might work for you. This is usually useful when your control is a "widget" form.



+2


a source


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>

      

0


a source







All Articles