C# 多次存储相同值的Onclick

C# 多次存储相同值的Onclick,c#,asp.net-mvc,dropzone.js,C#,Asp.net Mvc,Dropzone.js,考虑下面的代码片段 [HttpPost] [ValidateAntiForgeryToken] public async Task<ActionResult> Create(MyViewModel viewModel) { if (ModelState.IsValid) { //map properties here using (var context = new MyEntities())

考虑下面的代码片段

[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Create(MyViewModel viewModel)
{
        if (ModelState.IsValid)
        {
            //map properties here

            using (var context = new MyEntities())
            {
                context.Users.Add(user);
                context.SaveChanges();
            }

            if (Request.Files.Count > 0)
            {
                foreach (string fileName in Request.Files)
                {
                    HttpPostedFileBase file = Request.Files[fileName];
                    if (file != null && file.ContentLength > 0)
                    {
                       //do checks and upload file here
                    }
                }
            }
        }
        return RedirectToAction("Index", "Home");
}
我也遇到了问题,但我仍然有相同的问题

看起来该选项将改变行为,因此只向服务器发送一个请求

var myDropZone = new Dropzone("#dzUpload", {
    url: "/Home/Create",
    autoProcessQueue: false,
    previewsContainer: ".preview",
    uploadMultiple: true,
});

所以如果我是对的,插件会为你放入插件的每个文件发布表单,对吗??一种方法是生成GUID并在表单隐藏输入中维护它。所以每次你的插件发布时,它也会发布这个GUID。因此,根据Guid将insert语句更改为upsert(更新或插入)。。您还必须将此GUID与其他数据一起保存


因此,每次您打算插入时,请检查GUID是否已存在,如果已存在,请更新它,否则请插入新记录。

这正是我使用的方法,问题已得到解决
var myDropZone = new Dropzone("#dzUpload", {
    url: "/Home/Create",
    autoProcessQueue: false,
    previewsContainer: ".preview",
    uploadMultiple: true,
});