Post calls RedirectToAction but view specified in RedirectToAction is not rendered

Posted by W4IK on Stack Overflow See other posts from Stack Overflow or by W4IK
Published on 2010-03-12T16:04:53Z Indexed on 2010/03/12 16:07 UTC
Read the original article Hit count: 376

Filed under:
|

Here's some of the html

    <form id="frmSubmit" action="/Viewer" style="display:none;">            
        <div id="renderSubmit" class="renderReport">                 
            <input type="hidden" name="reportYear" id="reportYear" value="" />
            <input type="hidden" name="reportMonth" id="reportMonth" value="" />
            <input type="hidden" name="propIds" id="propIds" value="" />                
            <input type="hidden" name="reportName" id="reportName" value="" />                                                
            <input type="hidden" name="reportYearFrom" id="reportYearFrom" value="" />
            <input type="hidden" name="reportMonthFrom" id="reportMonthFrom" value="" />                
            <input type="hidden" name="reportYearTo" id="reportYearTo" value="" />
            <input type="hidden" name="reportMonthTo" id="reportMonthTo" value="" />                
        </div>    
    </form> 

a little further down the page

    <div id="reportList" class="renderReport">      
        <fieldset style="width:105%;">
        <legend class="reportStepLegend">Step 3. <br /> Click a report name below to view a report</legend>                
            <br />                 
            <% foreach (ReportMetaData item in (ReportMetaDataContainer)ViewData.Model) { %>                    
                <div>                        
                    <input id=<%=item.SSRSName%> type="button" class="reportLink" value="<%=item.DisplayName%>" /> 
                </div>                    
            <%}%>
        </fieldset>
    </div>

Here's the javascript that gets called when the button is clicked

   $('.reportLink').click(function() {
    if (CheckDateAndProps() === true) {
        $('#reportName').val(this.id);
        var formData = $("#frmSubmit").serializeArray();
        $.post('Home/PostViewer/', formData);
    }
});

Note...i did have the $.post like so earlier...but it didn't seem to make any difference

        $.post('Home/PostViewer/',
                        formData,
                        function(data) {
                            alert(data.Result);
                        }, "json");

Here's the controller code

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult PostViewer(string reportYear,
                               string reportMonth,
                               string propIds,
                               string reportName,
                               string reportYearFrom,
                               string reportMonthFrom,
                               string reportYearTo,
                               string reportMonthTo)
    {
        return RedirectToAction("Viewer");
    }

All is good in the world up to this point..I'm hitting the above method and all the values are populated.

Here's the get ActionResult method

    [AcceptVerbs(HttpVerbs.Get)]
    public ActionResult Viewer(string reportYear,
                               string reportMonth,
                               string propIds,
                               string reportName,
                               string reportYearFrom,
                               string reportMonthFrom,
                               string reportYearTo,
                               string reportMonthTo)
    {
        return View();
    }

I'm hitting this too...not seeing any values in the parameters...but that's just because I haven't passed them in yet...I don't think that's whats keeping the Viewer page from displaying.?

Now...one would one expect the Viewer view to be rendered...right?...well all I see is the page that this was called from...it never displays the Viewer page???!!?!?

Here's the routes from global.asax

        routes.MapRoute(
            "Viewer",                                      // Route name
            "Home/Viewer",                                 // URL with parameters
            new { controller = "Home", action = "Viewer" } // Parameter defaults                                
        );

        routes.MapRoute(
            "Default",                                              // Route name
            "{controller}/{action}/{id}",                           // URL with parameters
            new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
        );

I can browse directly to the page http://localhost:50083/Home/Viewer and when I do so I hit the get ActionResult method and the page renders just fine.

Any help is greatly appreciated!

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about jQuery