我正在回复一个控制器并设置Sessions。设置后,它会显示在第一个选项卡中,但是当我单击下一个加载另一个部分视图的选项卡时,我看不到会话设置。
order.cshtml with Tabs ...
<div id="tabs">
<ul class="nav nav-tabs">
<li><a href="#tabs-1">General</a></li>
<li><a href="#tabs-2">Item</a></li>
<li><a href="#tabs-3">Total</a></li>
</ul>
<div id="tabs-1">
@{Html.RenderPartial("_Partial_General_Tab", Model.GeneralTab);}
</div>
<div id="tabs-2">
@{Html.RenderPartial("_Partial_Item_Tab", Model.ItemTab);}
</div>
<div id="tabs-3">
Content for Tab 3 goes here.<br />
</div>
</div>
标签1
@model Mvc5.Models.ORDERMetadata
@{
var ordernumber = (int)Session["Order_Number"];
var princid_session = Session["PrincId"];
var custid_session = Session["CustId"];
}
OrderNumber: @ordernumber <br />
PrinicId: @princid_session <br />
CustID: @custid_session <br />
@using (Ajax.BeginForm("Edit", "Order",
new AjaxOptions
{
HttpMethod = "POST",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "target"
}))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
Enter model data here....
<button id="editorder" type="submit" class="btn btn-default">Save</button>
}
标签2
@model Mvc5.Models.ORDER_DETAILSMetadata
@{
var ordernumber = (int)Session["Order_Number"];
var princid_session = Session["PrincId"];
var custid_session = Session["CustId"];
}
OrderNumber: @ordernumber <br />
PrinicId: @princid_session <br />
CustID: @custid_session <br />
@using (Ajax.BeginForm("Items", "Order",
new AjaxOptions
{
HttpMethod = "POST",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "target"
}))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
Enter model data here....
<input type="submit" value="Add" class="btn btn-default" />
}
编辑控制器
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(ORDERMetadata model)
{
try
{
// update order
....
db.Entry(order).State = EntityState.Modified;
db.SaveChanges();
Session.Clear();
Session["Order_Number"] = model.Order_Number;
Session["PrincId"] = model.Princ_ID;
Session["CustId"] = model.Cust_ID;
return PartialView("_Partial_General_Tab", model);
}
catch (DbEntityValidationException ex)
{
return RedirectToAction("Index", "Error");
}
}