tags:

views:

94

answers:

2

I have a troubleshoot with my MVC project. I'm trying to do this:

On a view i'm loading some data on a jqgrid, and based on some selections of the user, i save those selections on a javascript VAR, and i passed it via $post to a Action of the controller, that action is supposed to call it's own view and load the data i passed previously.

Passing the data is working fine, but when the data reaches the new View (the second one), it simply don't load; i made a debug to confirm that the data is reaching the second view, but the page doesn´t shows.

Here is the code of my javascript:

$.post("/MyController/MyAction", { strParams: myParam });

Here is my Controller

    public ActionResult MyAction(string[] strParams){... return View(myobject);}

Here is my second view header:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/SiteIC.Master" Inherits="System.Web.Mvc.ViewPage<object[]>" %>

...

I don't see where is the problem, everything passed OK except for the second view that doesn't shows.

+1  A: 

You will only ever return the view MyAction using the return View(myobject); you could try

return View("yourviewname", myobject);

Kindness,

Dan

Daniel Elliott
+2  A: 

Where do you expect the view to load? When you do

$.post("/MyController/MyAction", { strParams: myParam });

this will simply post to the controller action and do nothing with the results (You can confirm that an AJAX call is performed using FireBug). If you want to do something with the result returned by the controller action you could try this:

$.post("/MyController/MyAction", { strParams: myParam }, function(result) {
    // result variable will contain the HTML rendered by the action
});

Also if you intend to inject the resulting HTML somewhere into the DOM your controller action needs to return a partial view instead of a full view:

public ActionResult MyAction(string[] strParams)
{
    // ...
    return PartialView("~/Views/MyController/MyAction.ascx", myobject);
}
Darin Dimitrov