在我的页面中,我显示了每个产品的产品和价格的订单 订单,用户可以更改每个产品的价格。
更改价格的功能运作良好但我的问题是用户必须刷新页面才能看到价格已更新。
有没有办法刷新视图和更新价格的相同操作。
更新价格的功能:
public ActionResult UPPDATEPrise(int VaraId, int pris, int kundId)
{
int _Orderid = GetLastOrderId();
SqlConnection conn = new SqlConnection("Data Source=ENTERPRISE-PC;Initial Catalog=Fakturor;Integrated Security=True");
String command = "UPDATE [Fakturor].[dbo].[Varor] SET pris="+pris+" WHERE [id]="+VaraId+"";
SqlCommand cmd = new SqlCommand(command,conn);
conn.Open();
cmd.ExecuteNonQuery();
return RedirectToAction("UdateOrderDetails", new { kundId = kundId, OrderId = _Orderid });
}
这是我返回视图的操作:
public ActionResult UdateOrderDetails(int kundId, int OrderId)
{
//Orders procuts
DataClasses1DataContext db = new DataClasses1DataContext();
var t1 = (from p in db.Varors
join
op in db.OrderVarors on p.id equals op.IdVara
where op.IdOrder == OrderId
select p).ToList();
ViewBag.OrderItems = t1;
//customer details
ViewBag.id= kundId;
//Order id
ViewBag.OrderId = OrderId;
// All products
ViewBag.varor=HamtarVaror();
return View("Create");
}
答案 0 :(得分:0)
听起来好像浏览器正在直接缓存页面。不确定这会起作用,但作为如何防止缓存的例子(不是最好的实现,只是一个例子):
设置一个标记,表示某些内容已在tempdata中更新。
public ActionResult UPPDATEPrise(int VaraId, int pris, int kundId)
{
// ALL YOUR CURRENT CODE....
TempData["IsCacheDisabled"] = true;
return RedirectToAction("UdateOrderDetails",
new { kundId = kundId, OrderId = _Orderid });
}
检查并更新缓存值:
public ActionResult UdateOrderDetails(int kundId, int OrderId)
{
// ALL YOUR CURRENT CODE....
if (TempData["IsCacheDisabled"] != null
&& (bool)TempData["IsCacheDisabled"])
{
var cache = HttpContext.Response.Cache;
cache.SetExpires(DateTime.UtcNow.AddDays(-1));
cache.SetValidUntilExpires(false);
cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
cache.SetCacheability(HttpCacheability.NoCache);
cache.SetNoStore();
}
return View("Create");
}