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

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"

};

}

Edit

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

{

@Html.ValidationSummary(true)

        UserInfo

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

            @Html.LabelFor(model => model.Name)        
       
            @Html.EditorFor(model => model.Name)             @Html.ValidationMessageFor(model => model.Name)        
            @Html.LabelFor(model => model.Password)        
       
            @Html.EditorFor(model => model.Password)             @Html.ValidationMessageFor(model => model.Password)        
            @Html.LabelFor(model => model.RealName)        
       
            @Html.EditorFor(model => model.RealName)             @Html.ValidationMessageFor(model => model.RealName)        
            @Html.LabelFor(model => model.UpdateDate)        
       
            @Html.EditorFor(model => model.UpdateDate)             @Html.ValidationMessageFor(model => model.UpdateDate)        
}
    @Html.ActionLink("Back to List", "Index")

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

function updateSuccess(data) {

if (data=="success") {

alert(‘保存成功!‘);

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

}

else

{

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

}

}

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;

///         ///

///

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

///         ///

///

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

///         ///

///

public string Password

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

///         ///

///

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

///         ///

///

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

#endregion Model

}

}

原文:http://www.cnblogs.com/Gxiaopan/p/4186299.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值