11
下面是一個例子方法,我有一個從我的應用程序中刪除一條記錄:ASP.NET MVC展會成功的消息
[Authorize(Roles = "news-admin")]
public ActionResult Delete(int id)
{
var ArticleToDelete = (from a in _db.ArticleSet where a.storyId == id select a).FirstOrDefault();
_db.DeleteObject(ArticleToDelete);
_db.SaveChanges();
return RedirectToAction("Index");
}
我想這樣做是顯示說像在索引視圖的消息:「Lorem ipsum文章已被刪除」我該怎麼做?由於
這是我目前的指數方法,以防萬一:
// INDEX
[HandleError]
public ActionResult Index(string query, int? page)
{
// build the query
var ArticleQuery = from a in _db.ArticleSet select a;
// check if their is a query
if (!string.IsNullOrEmpty(query))
{
ArticleQuery = ArticleQuery.Where(a => a.headline.Contains(query));
//msp 2011-01-13 You need to send the query string to the View using ViewData
ViewData["query"] = query;
}
// orders the articles by newest first
var OrderedArticles = ArticleQuery.OrderByDescending(a => a.posted);
// takes the ordered articles and paginates them using the PaginatedList class with 4 per page
var PaginatedArticles = new PaginatedList<Article>(OrderedArticles, page ?? 0, 4);
// return the paginated articles to the view
return View(PaginatedArticles);
}
我創建了一個NuGet包與發送從控制器(錯誤,警告,信息和成功)消息有助於查看的引導準備:https://www.nuget.org/packages/BootstrapNotifications/ – 2014-06-23 15:12:34