开发者

Post calls RedirectToAction but view specified in RedirectToAction is not rendered

开发者 https://www.devze.com 2022-12-22 14:50 出处:网络
Here\'s some of the html <form id=\"frmSubmit\" action=\"/Viewer\" style=\"display:none;\"> <div id=\"renderSubmit\" class=\"renderReport\">

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...the Viewer page is never rendered???!!?!?

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 ActionResult method and the page renders just fine.

Any help is greatly appreciated!

EDIT

Got it to work...had the put the buttons in the form so now the form looks like this

     <form id="frmSubmit" name="frmSubmit" action="/Home/Viewer" method="post" target="_blank"> 
        <div id="renderSubmit" class="renderReport">                 
            <input type="hidden" name="reportYear" id="reportYear" value="" />
            <input type="hidden" name="reportMonth" id开发者_JAVA技巧="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> 
        <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>   
    </form>

and the javascript looks like this

$('.reportLink').click(function() {
    if (CheckPropIds() === true) {
        $('#reportName').val(this.id);
        $("#frmSubmit").submit(); 
   }
});

it hits the controller code here

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Viewer(string reportYear,
                               string reportMonth,
                               string propIds,
                               string reportName,
                               string reportYearFrom,
                               string reportMonthFrom,
                               string reportYearTo,
                               string reportMonthTo)
    {
        if (reportName == "foobar")
        {                
            return RedirectToAction("FoobarView");
        }
        else
        {
            return View("Viewer");
        }
    }

and voila!...I see the view!...and if the reportName is foobar...I see the FoobarView!


Got it to work...had the put the buttons in the form so now the form looks like this

     <form id="frmSubmit" name="frmSubmit" action="/Home/Viewer" method="post" target="_blank"> 
        <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> 
        <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>   
    </form>

and the javascript looks like this

$('.reportLink').click(function() {
    if (CheckPropIds() === true) {
        $('#reportName').val(this.id);
        $("#frmSubmit").submit(); 
   }
});

it hits the controller code here

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Viewer(string reportYear,
                               string reportMonth,
                               string propIds,
                               string reportName,
                               string reportYearFrom,
                               string reportMonthFrom,
                               string reportYearTo,
                               string reportMonthTo)
    {
        if (reportName == "foobar")
        {                
            return RedirectToAction("FoobarView");
        }
        else
        {
            return View("Viewer");
        }
    }

and voila!...I see the view!...and if the reportName is foobar...I see the FoobarView!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号