• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Asp.Net Mvc4 Ajax提交数据成功弹框后跳转页面

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

1.cshtml页面代码

@model Model.UserInfo

@{     ViewBag.Title = "Edit";

    var options = new AjaxOptions()    

{        

Url = Url.Action("Edit", "Home"),        

LoadingElementId = "saving",        

LoadingElementDuration = 2000,         //   Confirm = "Are you sure you want to save this User?"        

OnSuccess = "updateSuccess"

};

}

<h2>Edit</h2>

@using (Ajax.BeginForm("Edit", null, options, new { role = "form" }))

{    

@Html.ValidationSummary(true)

    <fieldset>         <legend>UserInfo</legend>

        @Html.HiddenFor(model => model.Id)

        <div class="editor-label">             @Html.LabelFor(model => model.Name)         </div>         <div class="editor-field">             @Html.EditorFor(model => model.Name)             @Html.ValidationMessageFor(model => model.Name)         </div>

        <div class="editor-label">             @Html.LabelFor(model => model.Password)         </div>         <div class="editor-field">             @Html.EditorFor(model => model.Password)             @Html.ValidationMessageFor(model => model.Password)         </div>

        <div class="editor-label">             @Html.LabelFor(model => model.RealName)         </div>         <div class="editor-field">             @Html.EditorFor(model => model.RealName)             @Html.ValidationMessageFor(model => model.RealName)         </div>

        <div class="editor-label">             @Html.LabelFor(model => model.UpdateDate)         </div>         <div class="editor-field">             @Html.EditorFor(model => model.UpdateDate)             @Html.ValidationMessageFor(model => model.UpdateDate)         </div>

        <p>             <input type="submit" value="Save" />         </p>     </fieldset> }

<div>     @Html.ActionLink("Back to List", "Index") </div>

@section Scripts {     @Scripts.Render("~/bundles/jqueryval") }  

<script type="text/javascript">     

function updateSuccess(data) {               

  if (data=="success") {             

alert('保存成功!');             

window.location.href = "@Url.Action("Index", "Home")";                 

  }

else

{             

alert('保存失败!' + data);        

}    

}  

</script>

2.后台代码

  [HttpPost]
        public JsonResult Edit(UserInfo model)
        {
           //更新用户信息 ViewBag.flag为true表示保存成功,弹框
            string flag = BllFactory.GetUserBLL().SaveUserInfo(model);//数据处理
            return Json(flag, JsonRequestBehavior.DenyGet);
        }

3.Model

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace Model {    

public class UserInfo    

{        

#region Model        

private long _id;        

private string _name;        

private string _password;        

private string _realname;        

private DateTime? _updatedate = DateTime.Now;        

/// <summary>         ///        

/// </summary>        

public long Id         {             set { _id = value; }             get { return _id; }         }        

/// <summary>         ///        

/// </summary>        

public string Name         {             set { _name = value; }             get { return _name; }         }        

/// <summary>         ///        

/// </summary>        

public string Password        

{             set { _password = value; }             get { return _password; }         }        

/// <summary>         ///        

/// </summary>        

public string RealName         {             set { _realname = value; }             get { return _realname; }         }        

/// <summary>         ///        

/// </summary>        

public DateTime? UpdateDate         {             set { _updatedate = value; }             get { return _updatedate; }         }        

#endregion Model    

}

}

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Asp.NetMVCIdentity2.2.1使用技巧(一)发布时间:2022-07-10
下一篇:
asp.net下载EXCEL文件发布时间:2022-07-10
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap