zoukankan      html  css  js  c++  java
  • 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,200),                    
                    new SqlParameter("@msg",SqlDbType.NVarChar,1000),
                    new SqlParameter("@msg_by",SqlDbType.VarChar,20)
                };
                paramter[0].Value = model.Title;
                paramter[1].Value = model.Msg;
                paramter[2].Value = LoginStaffID;
                if (SqlDbHelper.ExecuteSql(strSql, paramter) > 0)
                {
                    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>
  • 相关阅读:
    linux下使用yum安装mysql、tomcat、httpd
    C++中 模板Template的使用
    Linux如何在虚拟机中挂载iso yum源
    实例讲解Nginx下的rewrite规则
    WorldWind源码剖析系列:图像助手类ImageHelper
    WorldWind源码剖析系列:缓冲类Cache
    WorldWind源码剖析系列:绘制参数类DrawArgs
    WorldWind源码剖析系列:设置类SettingsBase
    WorldWind源码剖析系列:经纬度格网类LatLongGrid
    WorldWind源码剖析系列:相机类CameraBase
  • 原文地址:https://www.cnblogs.com/myjacky/p/3385110.html
Copyright © 2011-2022 走看看