ユーザーが追加されたときに警告メッセージを表示します。それはスムーズに起こりますが、別のアクションからブラウザの戻る矢印を押すと、警告メッセージが表示されます。あなたのIndexメソッドで他のアクションから戻る矢印をクリックするとTempdataがクリアされない?
//this is my partial view
<div class="row" id="alerts">
<div class="col-lg-12">
@if (TempData["Success"] != null)
{
<div class="alert alert-success alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-
hidden="true">x</button>
<h4><i class="icon fa fa-ban"></i> Alert!</h4>
@TempData["Success"]
</div>
}
</div>
</div>
//this is my controller
public ActionResult Add(CreateViewModel objCreate)
{
userRepo.AddUser(objCreate);
TempData["Success"] = "User Added Successfully!";
return RedirectToAction("Index");
}
//this is my view
<div class="col-md-10 col-md-offset-2">
@Html.Partial("_Alerts")
@RenderBody()
</div>
ありがとう!それはうまく動作しますが、まだそれは良い方法ですか? –
@AnandShresthaはあなたのニーズに依存しますが、上記の例では、その特定のアクションのキャッシュを無効にします。これは、インデックスにリダイレクトされた後でクリックしたときに起こります。 [Here](https://msdn.microsoft.com/en-us/library/system.web.mvc.outputcacheattribute(v = 118).aspx)は、関連するドキュメントであり、[関連するその他の質問](http ://stackoverflow.com/questions/20895489/outputcache-setting-inside-my-asp-net-mvc-web-application-multiple-syntax-to-pr)。それが役に立てば幸い。 – granit