0
我期待在不同的崗位,這樣在按一下按鈕,我們可以做兩個動作。渲染按鈕動態部分的觀點點擊
我的aspx頁面包含表單,並在按鈕上單擊它將提交表單到控制器,我在我的控制器中使用表單數據並基於我的表單中的值我渲染部分視圖,我要顯示我的部分視圖在我的ASPX。
我做下面的步驟:
<form id="StatsForm" name="StatsForm" action="../Stats/Index/" method="POST"
enctype="multipart/form-data">
<%= Html.AntiForgeryToken()%>
<% Html.RenderPartial("OptionalFields"); %>
</form>
<script type="text/javascript" language="javascript">
//<![CDATA[
$(document).ready(function() {
$("#GetReport").click(function() {
$("form[name=StatsForm]").submit();
});
});
//]]>
</script>
我的控制器:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(FormCollection form)
{
// Deal with the form
var strId= Convert.ToInt32(form["manufacturerId"]);
var str1Id= Convert.ToInt32(form["reportId"]);
var str2Id= Convert.ToInt32(form["categoryId"]);
var str3Id= Convert.ToInt32(form["retailerId"]);
var str4Id= Convert.ToInt32(form["countryId"]);
var str5Id= Convert.ToInt32(form["regionId"]);
var str6Id= (form["ManufacturerWidgetId"]);
var startDate = new DateTime(1, 1, 1, 0, 0, 0, 0);
var endDate = new DateTime(1, 1, 1, 0, 0, 0, 0);
if (!String.IsNullOrEmpty(form["StartDate"]))
{
startDate = Convert.ToDateTime(form["StartDate"]);
}
if (!String.IsNullOrEmpty(form["EndDate"]))
{
endDate = Convert.ToDateTime(form["EndDate"]);
}
var reportName = _reportRepository.GetReport(reportId);
var stats = new Stats
{
};
switch (reportName.Code)
{
case "ABC":
return RedirectToAction("InterStats",
new
{
});
break;
case "XYZ":
return RedirectToAction("ParametersCumLeads",
new
{
});
break;
case "IMP":
break;
}
我的部分觀點:
[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
public ActionResult InterStats(int str1Id, int str2Id, DateTime startDate, DateTime endDate)
{
var str = _manufacturerWidgetsRepository.GetManufacturerWidgetByManufacturerAndCountry(manufacturerId, countryId);
var report = new ABCReport();
var reportList = new List<ReportList>(); // a list of my anonymous type without the relationships
report.reportList = new List<Record>();
var count = 1;
foreach (var mw in str)
{
// I am doing some function
// Create the data for the report
}
return PartialView(report);
}
,我試圖在我的aspx,以顯示我的部分觀點。 我的問題是不用點擊我的提交按鈕兩次,我怎麼能在我的aspx提交表單到我的控制器,也注入我的部分景色。