我有一个局部视图,其中包含一个包含多个下拉菜单和一个提交按钮的表单。提交操作调用用HttpPost修饰的Controller Action Method。当我运行应用程序时,页面加载正常,并且提交在第一次完美运行。如果我离开页面并返回到它并尝试提交,它根本不会触及Action方法 - 但会加载包含先前值的页面。
我的观点
<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>
我的控制器
[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 });
}
我不确定我做错了什么!
答案 0 :(得分:1)
我能够通过重写表单定义来解决这个问题:
@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>
}
答案 1 :(得分:0)
我承认这是一个黑暗中的镜头,但尝试在上面添加[NoCache]装饰器 控制器中的[HttpPost]。