public ActionResult Contact(Message model)
{
model.WriteTime = DateTime.Now;
model.IsRead = false;
db.Message.Add(model);
db.SaveChanges();
JsonResult json = new JsonResult();
json.Data = new
{
result = "true"
};
return json;
}
$.ajax({
type: 'post',
url: '/Student/Add',//路径为添加方法
data: '&name=' + sname + '&sex=' + ssex + '&birsthday=' + sbirsthday + '&sclass=' + sclass,//参数的个数和名字要和方法的名字保持一致
success: function (json)//返回的是Json类型的
{
//判断是否成功
if (json.result == "true") {
alert('恭喜你,增加成功!');
}
else {
alert('抱歉,增加失败!');
}
}
});
评论区