我以爲TempData在一次刷新或頁面重定向後應該變爲空。我的頁面需要刷新兩次才能清除數據,雖然這不是我想要的,但是如何在1次刷新/重定向之後將其清空?刷新後TempData不爲空
@using (Html.BeginForm())
{
<div class="form-group">
<button class="btn btn-default" type="submit">test</button>
</div>
}
public void test()
{
List<int> integers = new List<int>();
integers.Add(10);
integers.Add(20);
//First Refresh and myList still has values when I want it to be null
List<int> myList = (List<int>)TempData["test"]; // Take the value from the current data variable
if (myList == null) // Not yet stored in session, create a new list and store it as a session variable
{
myList = new List<int>();
TempData.Add("test", myList);
}
myList.AddRange(integers); // Add a new entry
}
應該可用於未來* *請求 - 否則,它不會是非常有用的。 –
好的。只有當動作再次是test()時,我將如何保存下一個請求的數據?並清除任何其他請求的數據。 –
顯示你的動作代碼。 – Kamo