gpt4 book ai didi

jquery - Post 调用 RedirectToAction 但 RedirectToAction 中指定的 View 未呈现

转载 作者:行者123 更新时间:2023-12-01 05:10:10 27 4
gpt4 key购买 nike

这是一些 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>

页面再往下一点

    <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>

这是单击按钮时调用的 javascript

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

注意...我确实有像之前那样的 $.post...但它似乎没有任何区别

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

这是 Controller 代码

    [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");
}

到目前为止,世界上一切都很好。我正在使用上述方法,所有值都已填充。

这是获取ActionResult方法

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

我也遇到了这个问题...没有看到参数中的任何值...但这只是因为我还没有将它们传递...我不认为这会阻止查看器页面显示?

现在...人们会希望呈现查看器 View ...对吗?...好吧,我所看到的只是调用该 View 的页面...查看器页面从未呈现???! !?!?

这是来自 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
);

我可以直接浏览页面 http://localhost:50083/Home/Viewer当我这样做时,我点击了 ActionResult 方法,页面渲染得很好。

非常感谢任何帮助!

编辑

让它工作...将按钮放入表单中所以现在的表单看起来像这样

     <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>

JavaScript 看起来像这样

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

它点击这里的 Controller 代码

    [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");
}
}

瞧!...我看到了 View !...如果 reportName 是 foobar...我看到了 FoobarView!

最佳答案

让它工作...将按钮放入表单中所以现在的表单看起来像这样

     <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>

JavaScript 看起来像这样

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

它点击这里的 Controller 代码

    [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");
}
}

瞧!...我看到了 View !...如果 reportName 是 foobar...我看到了 FoobarView!

关于jquery - Post 调用 RedirectToAction 但 RedirectToAction 中指定的 View 未呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2433972/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com