如何在mvc4中上传json文件以在表中输入数据

时间:2014-03-15 18:58:25

标签: asp.net-mvc asp.net-mvc-3 asp.net-mvc-4 asp.net-mvc-5

我的数据库采用以下格式生成的json文件

[{"UserInfoID":"57adb1e8-27ab-e311-afb2-eca86bf5549a","DbType":"OFFLINE","UserID":"d3f3b6a6-77aa-436a-a73c-d6655566888b","GraphID":"56adb1e8-27ab-e311-afb2-eca86bf5549a","UserLevelEnumId":"00000000-0000-0000-0000-000000000000","Title":"Mr/Mrs","FirstName":"Neeraj","MiddleName":null,"LastName":"Mehta","Birthdate":"\/Date(699388200000)\/","Gender":"Male","Email":"neer.srmiet@gmail.com","MobileNo":"+918950333123","Country":"India","Zipcode":133201,"UserLevel":999,"CountFollowers":0,"CountFollows":0,"CountFiles":0,"CountPhotos":0,"Quote":"Empowering Education","AvatarURL":"/UserFiles/Images/X50/IMAG1289_1vv4djTgspjjsl87fquality_50.jpg","PosterURL":null,"isVerified":true,"VerificationCount":0,"UserEnumType":"USER","UserCreatorId":"d3f3b6a6-77aa-436a-a73c-d6655566888b"}

我已将此数据下载到文件中,现在我想将此数据上传到具有相同结构和相同属性的其他数据库中 如何从文件和建议中上传这个?

1 个答案:

答案 0 :(得分:0)

  1. 如果您还没有,请创建一个与此对象匹配的课程(让我们称呼此课程'用户')。
  2. 如果要使用ajax上传此json数据,请创建以下操作:

    [HttpPost]
    public ActionResult(User user) {
    // Add input validation here.
    // Add the user entity to the database.
    UsersContext context = new UsersContext();
    context.Users.Add(user);
    context.SaveChanges(); 
    }