问题描述
大家好, 我正在尝试制作一个多步骤jquery表单来上传简历, 和我通过json将数据发送到db并使用Linq to Entity, 我有4张桌子: 1-基本信息 2-教育信息 3-工作经验和 4-技能 当用户点击提交按钮时我需要将edu,工作和技能信息添加到另一个表中,但我需要生成的userid作为外键插入到这些表中, 不知道如何获取id以及如何将其作为参数传递到这些表中: 我的json代码:
Hi guys, I am trying to make a muti step jquery form for uploading resume, and i send data to db by json and using Linq to Entity, I have 4 tables: 1- Basic info 2- education info 3- work experience and 4- skills when user click on submit button i need to add edu and work and skill info into another tables but i need the generated userid to insert into those tables as foreign keys, dont know how to get id and how to pass it as parameters into those tables: its my json code:
<script>
windows.onload = function () {
$.getFormObject = function (selector) {
var obj = {};
var propArr = $(selector).serializeArray();
$.each(propArr, function (i, p) {
obj[p.name] = p.value;
});
return obj;
};
};
</script>
<script>
// window.onload =
$(function () {
$('#btnSubmit').on('click', function () {
var formObj = $.getFormObject('#msform');
formObj.Id = 0;
var dataToSend = { resume: formObj };
$.ajax({
url: '/Resume.aspx/AddBaseResume',
contentType: 'application/json',
dataType: 'json',
type: 'post',
data: JSON.stringify(dataToSend),
success: function (id) {
var $messageContainer = $('.message-container');
$messageContainer.html('');
$('<div class="alert alert-success" />')
.html('Your ID is: ' + id.d)
.hide()
.fadeIn()
.appendTo($messageContainer);
//reloadGrid();
},
error: function () {
var $messageContainer = $('.message-container');
$messageContainer.html('');
$('<div class="alert alert-danger" />')
.html('Oops! Can not add you right now! :(')
.hide()
.fadeIn()
.appendTo($messageContainer);
}
});;
});
});
</script>
及其我的webmethod:
and its my webmethod:
[WebMethod]
public static string AddBaseResume(tblResume resume)
{
var db = new SHDBEntities1();
db.tblResumes.Add(resume);
db.SaveChanges();
return resume.Id.ToString();
}
[WebMethod]
public static string AddEducation(tblEducation edu)
{
var db = new SHDBEntities1();
db.tblEducations.Add(edu);
db.SaveChanges();
return edu.Id.ToString();
}
提前感谢任何帮助或建议!
thanks in advance for any help or suggestion!
推荐答案
.getFormObject = function(selector){ var obj = {}; var propArr = .getFormObject = function (selector) { var obj = {}; var propArr =
(selector).serializeArray(); (selector).serializeArray();
.each(propArr,function(i,p){ obj [p.name] = p.value; }); return obj; }; }; < / script > < script > // window.onload = .each(propArr, function (i, p) { obj[p.name] = p.value; }); return obj; }; }; </script> <script> // window.onload =