I am looking at different posts so that on button click can we do two actions.
My aspx page contains form and on button click it will submit form to controller and I am using form data in my controller and based up on the values in my form I am rendering partial views and I wan tto show my partial view in my aspx .
I am doing below steps :
<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>
My controller :
[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;
}
My partial view:
[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);
}
And I am trying to display my partial view in my aspx. My question is without clicking my submit button twice how can I submit form to my controller and also inject my partial views in my aspx.