如何显示警报消息像"成功插入"使用ASp.net MVC3插入到数据库后, [英] How to show Alert Message like "successfully Inserted" after inserting to DB using ASp.net MVC3

查看:88
本文介绍了如何显示警报消息像"成功插入"使用ASp.net MVC3插入到数据库后,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何写一个code用于显示警告信息:已成功注册,用户数据存储在数据库之后,使用MVC

How to write a code for displaying the alert message: "Successfully registered", after user data is stored in database, using MVC

我使用Asp.Net MVC3,C#,实体模型。

I am using Asp.Net MVC3, C#, Entity Model.

推荐答案

尝试使用的TempData

public ActionResult Create(FormCollection collection) {
  ...
  TempData["notice"] = "Successfully registered";
  return RedirectToAction("Index");
  ...
}

然后,在你的索引视图,或母版页等,你可以这样做:

Then, in your Index view, or master page, etc., you can do this:

<% if (TempData["notice"] != null) { %>
  <p><%= Html.Encode(TempData["notice"]) %></p>
<% } %>

或者,在一个的Razor视图:

Or, in a Razor view:

@if (TempData["notice"] != null) {
  <p>@TempData["notice"]</p>
}

从MSDN报价(网页已不存在截至2014年,归档副本<一个href=\"http://web.archive.org/web/20111124074512/http://msdn.microsoft.com/en-us/library/dd394711.aspx\">here):

的操作方法可以在控制器的TempDataDictionary对象,它会调用控制器的RedirectToAction方法来调用下一个动作之前存储数据。该TempData的属性值存储在会话状态。该TempDataDictionary值设置可以从对象的值,然后处理或显示它们后调用任何操作方法。 TempData的价值仍然存在,直到它被读取或直到会话超时。坚持TempData的这种方式使得场景,如重定向,因为在TempData的值就可以超越单一的请求。

An action method can store data in the controller's TempDataDictionary object before it calls the controller's RedirectToAction method to invoke the next action. The TempData property value is stored in session state. Any action method that is called after the TempDataDictionary value is set can get values from the object and then process or display them. The value of TempData persists until it is read or until the session times out. Persisting TempData in this way enables scenarios such as redirection, because the values in TempData are available beyond a single request.

这篇关于如何显示警报消息像&QUOT;成功插入&QUOT;使用ASp.net MVC3插入到数据库后,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆