Reputation: 53
I have a partial view that has a form with multiple drop-downs and a submit button. The submit action calls the Controller Action Method decorated with HttpPost. When I run the app, the page loads fine and the submit works perfectly the first time. If I navigate out of the page and back to it and try the Submit, it does not hit the Action method at all - but loads the page with the previous values.
My View
<h4>Filters</h4>
<b>Season </b>
<br />
@Html.DropDownList("SeasonTables", ViewBag.Seasons as SelectList, "...Select Season...", new { @class = "form-control", id = "cmbSeason", style = "width:250px;" })
<br />
<br />
<b>Product Group </b>
<br />
@Html.DropDownList("ProductGrpTable", ViewBag.ProductGrp as SelectList, "...Select Product Grp...", new { @class = "form-control", id = "cmbProductGrp", style = "width:250px;" })
<br />
<br />
<b>Delivery Group </b>
<br />
@Html.DropDownList("DeliveryGrpTable", ViewBag.ProductDelGrp as SelectList, "...Select Delivery Grp...", new { @class = "form-control", id = "cmbDeliveryGrp", style = "width:250px;" })
<br />
<br />
<b>Division </b>
<br />
@Html.DropDownList("DivisionTable", ViewBag.DivisionList as SelectList, "...Select Division...", new { @class = "form-control", id = "cmbDivision", style = "width:250px;" })
<br />
<br />
<br />
<br />
<br />
<p>
<input type="submit" value="submit" />
</p>
</div>
</form>
</div>
My Controller
[HttpPost]
public ActionResult Index(FormCollection filterData)
{
Session.Remove("filterData");
LSBusinessObject.Filter filter = new LSBusinessObject.Filter();
filter.Season = filterData["SeasonTables"];
filter.ProductGp = filterData["ProductGrpTable"];
filter.ProductDelGp = filterData["DeliveryGrpTable"];
filter.Division = filterData["DivisionTable"];
Session["filterData"] = filter;
lsBusinessLayer.RunSSIS(filter.Season, filter.ProductGp, filter.ProductDelGp, filter.Division);
//persist the values
var seasonListData = from s in lsBusinessLayer.Seasons
orderby s.season descending
select new
{
seasonname = s.season,
seasonID = s.seasonID
};
SelectList seasonList = new SelectList(seasonListData, "seasonname", "seasonname", filter.Season);
ViewBag.Seasons = seasonList;
var ProductGpListData = from pg in lsBusinessLayer.ProdGrps
orderby pg.Product_Group_Name
select new
{
pgID = pg.Product_Group_ID,
pgName = pg.Product_Group_Name
};
SelectList pgList = new SelectList(ProductGpListData, "pgName", "pgName", filter.ProductGp);
ViewBag.ProductGrp = pgList;
var ProductDelGpListData = from pg in lsBusinessLayer.ProdDelGrps
orderby pg.Product_Delivery_Group_Name
select new
{
pgID = pg.Product_Delivery_Group_ID,
pgName = pg.Product_Delivery_Group_Name
};
SelectList pgDelList = new SelectList(ProductDelGpListData, "pgName", "pgName", filter.ProductDelGp);
ViewBag.ProductDelGrp = pgDelList;
var DivisionListData = from pg in lsBusinessLayer.Divisions
orderby pg.Product_Division_Name
select new
{
pgID = pg.Product_Division_ID,
pgName = pg.Product_Division_Name
};
SelectList divList = new SelectList(DivisionListData, "pgName", "pgName", filter.Division);
ViewBag.DivisionList = divList;
Session["UpdateResult"] = "";
Session["ShowAll"] = "false";
return RedirectToAction("Index", "LScontrol", new { filterData = filter });
}
I am not sure what I'm doing wrong!
Upvotes: 0
Views: 894
Reputation: 53
I was able to solve this by re-writing the form definition as follows:
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { @class = "FilterForm" }))
{
<h4>Filters</h4>
<b>Season </b>
<br />
@Html.DropDownList("SeasonTables", ViewBag.Seasons as SelectList, "...Select Season...", new { @class = "form-control", id = "cmbSeason", style = "width:250px;" })
<br />
<br />
<b>Product Group </b>
<br />
@Html.DropDownList("ProductGrpTable", ViewBag.ProductGrp as SelectList, "...Select Product Grp...", new { @class = "form-control", id = "cmbProductGrp", style = "width:250px;" })
<br />
<br />
<b>Delivery Group </b>
<br />
@Html.DropDownList("DeliveryGrpTable", ViewBag.ProductDelGrp as SelectList, "...Select Delivery Grp...", new { @class = "form-control", id = "cmbDeliveryGrp", style = "width:250px;" })
<br />
<br />
<b>Division </b>
<br />
@Html.DropDownList("DivisionTable", ViewBag.DivisionList as SelectList, "...Select Division...", new { @class = "form-control", id = "cmbDivision", style = "width:250px;" })
<br />
<br />
<br />
<br />
<br />
<p>
<input type="submit" value="submit" />
</p>
}
Upvotes: 1
Reputation: 1305
I admit this is a shot in the dark, but try adding the [NoCache] decorator above [HttpPost] in your controller.
Upvotes: 0