MVC服务器前台提示
[HttpPost]
public ActionResult AddMsg(MsgModel model)
{
string strSql = "insert into tbl_msg(title,msg,msg_by,msg_date,status) values(@title,@msg,@msg_by,getdate(),'A')";
SqlParameter[] paramter ={
new SqlParameter("@title",SqlDbType.NVarChar,),
new SqlParameter("@msg",SqlDbType.NVarChar,),
new SqlParameter("@msg_by",SqlDbType.VarChar,)
};
paramter[].Value = model.Title;
paramter[].Value = model.Msg;
paramter[].Value = LoginStaffID;
if (SqlDbHelper.ExecuteSql(strSql, paramter) > )
{
TempData["SuccKey"] = "添加成功,是否继续添加呢?";//前台弹出JS
}
else
{
ModelState.AddModelError("addError", "发生错误,留言失败!");//文本显示
return View(model);
}
return View();
}
<!DOCTYPE html>
<html>
<head>
<title>添加留言</title>
<link type="text/css" href="@Url.Content("~/Content/Site.css")" rel="Stylesheet" />
</head>
<body>
<script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>MsgModel</legend> <div class="editor-label">
@Html.LabelFor(model => model.Title)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Title)
@Html.ValidationMessageFor(model => model.Title)
</div> <div class="editor-label">
@Html.LabelFor(model => model.Msg)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Msg)
@Html.ValidationMessageFor(model => model.Msg)
</div>
用户名:@Html.DropDownList("ddlStaff_id", (SelectList)ViewBag.list, "请选择")
<p>
<input type="submit" value="添加留言" />
@Html.ValidationMessage("addError")
</p>
</fieldset>
} @if (TempData["SuccKey"]!=null)
{
<script type="text/javascript">
if (!confirm('@HttpUtility.JavaScriptStringEncode(Convert.ToString(TempData["SuccKey"]))')) {
window.location.href="Index";
}
</script>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
</body>
</html> 运行效果如下:
<form action="/Msg/AddMsg" method="post">
.......
<p>
<input type="submit" value="添加留言" />
<span class="field-validation-valid" data-valmsg-for="addError" data-valmsg-replace="true"></span>
</p>
</form>
<script type="text/javascript">
if (!confirm('添加成功,是否继续添加呢?')) {
window.location.href="Index";
}
</script>
<a href="/Msg">Back to List</a>
MVC服务器前台提示的更多相关文章
- 在mvc中弹出提示框
在传统的WebForm中,我们要弹出一个alert提示框非常简单,只要在页面中输出alert即可,比如输出: Response.Write("<script >alrer('我是 ...
- 在SharePoint 2013 场中移除服务器,提示 cacheHostInfo is null 错误
Problem 在SharePoint 2013 场中移除服务器,提示 cacheHostInfo is null 错误 Resolution 这是由于SharePoint 2013中分布式缓存实例( ...
- 开发环境运行正常,发布服务器后提示HTTP 错误 403.14 - Forbidden
一.发布服务器后报错 今天在项目发布中遇到一件奇怪的事,开发完成的项目,发布到服务器上时 1. 发布到A服务器,一切正常 2. 发布到B服务器,提示403服务器错误 在同事电脑上重新打包发布代码,并发 ...
- ssh执行远程服务器脚本 提示php: command not found
ssh执行远程服务器脚本 提示php: command not found 设置环境变量 一台机器作为管理机,来管理其他服务器,并通过key认证,免密码登陆的. 在管理机上通过ssh登陆到其他服务器来 ...
- toroiseSVN 无法连接服务器,提示unable connect to ……url 参数错误
之前使用的好好的,有天突然提示无法连接repository url,能ping通服务器,就是一直报错,找了很多方法,如: 1.删除缓存及缓存文件 2.删除软件并重新安装 3.关闭windows防火墙 ...
- MVC 服务器文件下载
文件上传到服务器后下载 window.open 与window.location.href 对txt 或是pdf文件执行的操作是打开,而非下载 mvc controller 自带有如下方法 p ...
- MVC中前台如何向后台传递数据------$.get(),$post(),$ajax(),$.getJSON()总结
一.引言 MVC中view向controller传递数据的时候真心是一个挺让人头疼的一件事情.因为原理不是很懂只看一写Dome,按葫芦画瓢只能理解三分吧. 二.解读Jquery个Ajax函数 $.ge ...
- spring mvc:exclude-mapping错误提示
今天搭建一个java web项目时,增加了一个登录的拦截器,主要功能就是未登录的用户无法访问系统的任何页面. 先说明下我的web项目springmvc的版本以及刚开始配置的拦截器: springmvc ...
- mvc jsonresult 前台、后台解析
背景介绍:asp.net中使用json对象传参;mvc中可以直接使用jsonresult这个对象 一:怎么使用jsonresult public JsonResult text() { var str ...
随机推荐
- Android消息处理机制(Handler 与Message)---01
一.handler的使用场景为么会有handler?(部分内容图片摘自http://www.runoob.com/w3cnote/android-tutorial-handler-message.ht ...
- telnet不通11211端口,防火墙
问题描述: 按照官网步骤,虚拟机里安装并启动memcached, 虚拟机里自己telnet11211端口可以连接, 使用Xmanager22端口可以连接到虚拟机,但是始终telnet不同11211端口 ...
- Hibernate,JPA注解@OneToOne_JoinColumn
一对一(One-to-one),外键关联 用例代码如下: 数据库DDL语句 1,CAT表 create table CAT ( id CHAR) not null, create_time ), up ...
- 1014 C语言文法定义与C程序的推导过程 程序:冒泡算法C程序(语法树)
阅读并理解提供给大家的C语言文法文件. 参考该文件写出一个自己好理解版的现实版的完整版的C语言文法. 给出一段C程序,画出用上述文法产生这段C程序的完整语法树. 程序:冒泡算法C程序 点此文字查看原图 ...
- (翻译)理解Java当中的回调机制
原文地址:http://cleancodedevelopment-qualityseal.blogspot.com/2012/10/understanding-callbacks-with-java. ...
- NotificationObject.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.C ...
- java实现贪吃蛇游戏
最简单的4个java类就可以实现贪吃蛇: main函数: package tcs; public class GreedSnake { public static void main(String[] ...
- 调试器不能连接到STM32的问题与解决办法
很多人都碰到过调试器不能连接到STM32的问题,不管是IAR的J-Link还是Keil的ULink,或者是ST的ST-Link.出现这个问题时,调试软件会提示不能建立与Cortex-M3的连接,或提示 ...
- JAVA中生成Excel方法
java 操作 Excel 最常用的就是JXL(java excel api)和POI,今先看下JXL吧.首先可以到 http://www.andykhan.com/jexcelapi/downloa ...
- (4)Redis 资料
Redis是一种面向“键/值”对类型数据的分布式NoSQL数据库系统,特点是高性能,持久存储,适应高并发的应用场景. Redis Home http://redis.io/ MSOpenTech/re ...