新增,修改,删除是我们使用最多和最基础的操作,我们先看一下新增操作,
在视图中:
function faaty() {//对应着新增按钮
var AclassUser = $("#AclassUser").val();//对应着文本框给的ID
var BclassUser = $("#BclassUser").val();
var CclassUser = $("#CclassUser").val();
var Broadband = $("#Broadband").val();
var FixedLine = $("#FixedLine").val();
var PHS = $("#PHS").val();
var Other = $("#Other").val();
var KeyPointsWork = $("#KeyPointsWork").val();
var RecoveryPlan = $("#RecoveryPlan").val();
if (AclassUser != “” && BclassUser != “” && CclassUser != “” && Broadband != “” && FixedLine != “” && PHS != “” && Other != “” && KeyPointsWork != “” && RecoveryPlan != “”) {//数据不能为空
$.post(“WorkPlan”,//提交的方式
{ AclassUser: AclassUser, BclassUser: BclassUser, CclassUser: CclassUser, Broadband: Broadband, FixedLine: FixedLine, PHS: PHS, Other: Other, KeyPointsWork: KeyPointsWork, RecoveryPlan: RecoveryPlan},//与控制器那边的相对于
function (data) {//键值对
if (data.State == true) {//提交成功
layer.alert(data.Text);
TPWorkPlan.reload();
} else {
layer.alert(data.Text);
}
});
} else {//提交失败
layer.alert(“请将数据输入完整!”);
}
}
在控制器中:
public ActionResult JobDiary(string WorkHours, string WorkItem, string ContaMode, string Contacts, string JobContent,
string fujiantuj)对应着在数据库中给的字段
{
ReturnJson msg = new ReturnJson();
if (!string.IsNullOrEmpty(WorkHours) && !string.IsNullOrEmpty(WorkItem) && !string.IsNullOrEmpty(ContaMode) && !string.IsNullOrEmpty(Contacts) && !string.IsNullOrEmpty(JobContent)
&& !string.IsNullOrEmpty(fujiantuj))
{
JobDiary modAcademe = new JobDiary(); //
modAcademe.WorkHours = WorkHours;
modAcademe.WorkItem = WorkItem;
modAcademe.ContaMode = ContaMode;
modAcademe.Contacts = Contacts;
modAcademe.JobContent = JobContent;
myModel.JobDiary.Add(modAcademe);
myModel.SaveChanges();
msg.State = true;//提交成功
msg.Text = “日志新增成功”}
else
{
msg.State = false;//提交失败
msg.Text = “日志提交失败”;
}
return Json(msg, JsonRequestBehavior.AllowGet);
}
数据缺少:
提交成功后到数据库:
新增操作
最新推荐文章于 2024-04-16 00:30:29 发布