0

キャッシュに問題があり、見つけられるすべての解決策を試しました。

テーブルに 1 つの行が挿入される単純な作成画面があります (ただし、既存の行を編集するときにも同じ問題が発生します)。

行が作成されると、ユーザーは前の画面に戻り、まだ古いデータが表示されます。(編集と同じ問題)

ページを更新しても違いはありません。異なるブラウザには同じ問題があります。データベースにデータが正常に追加されました。アプリケーションを再表示することによってのみ、画面上のデータが更新されます。

私が試したこと:

1:

DataContext.Refresh(RefreshMode.OverwriteCurrentValues)

2:

[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]

3:

ModelState.Clear()

どれも違いはありませんでした。編集や作成でこの問題が発生したことはないので、何か不足しているに違いありません。どんな助けでも大歓迎です!

以下は、コントローラーの関連部分です。

ISISDataContext db = new ISISDataContext(StudentISIS.Properties.Settings.Default.ISISConn.ToString());

    public ActionResult Index()
    {
        var student = (ISIS2Models.Student)Session["CurrentUser"];

        return View(student);
    }

    public ActionResult STGCreate(int id)
    {
        var enrolment = db.Enrolments.Single(e => e.EnrolmentID == id);
        return View(enrolment);
    }


    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult STGCreate([Bind(Exclude = "Id")] StudentGrade STGToCreate, FormCollection collection)
    {
        var STG = new StudentGrade();

        STG.Grade = collection["StudentTG"];
        STG.EnrolmentID = int.Parse(collection["Enrolment"]);
        STG.DateChanged = DateTime.Now;

        db.StudentGrades.InsertOnSubmit(STG);
        db.SubmitChanges();

        return RedirectToAction("Index");
    }

編集:

以下は、登録をループして成績を表示するインデックス ビューのコードです。

<%foreach (var en in Model.Enrolments) {%>
//Some table stuff
<td>
<%try
        { %>
      <%= Html.ActionLink(en.StudentGrades.Grade,"STGEdit",new {controller = "Progress", id = en.StudentGrades.StudentGradeID})%>
      <%}
        catch (NullReferenceException) {%><%= Html.ActionLink("Set","STGCreate",new {controller = "Progress", id = en.EnrolmentID})%><% } %>
      </td>
//Some more table stuff

<%}%
4

1 に答える 1

1

行はどこから来るのですか?それはあなたの ISIS2Models.Student クラスですか? メソッドにコードがほとんどないためだと思いますIndex

そうであり、それをセッションに保存している場合、その値は更新されていないため、その値を取得するとIndex、同じ古い値が保持されます。

を呼び出すたびに、更新されたモデルをデータベースから取得する必要がありますIndex。このようないくつかの方法:

public ActionResult Index()
{
    var currentUser = (ISIS2Models.Student)Session["CurrentUser"];

    var student = GetStudentById(currentUser.ID);//this will get the up-to-date student record from the DB

    return View(student);
}
于 2013-04-10T10:48:02.437 に答える