尝试在数据库中发布数据,但我得到的只是空字段

问题描述

嘿,所以我有一个模式弹出窗体,在该窗体中,我必须上传文件并将数据发布到数据库。当我按Submit时,我的RedirectToAction方法出现错误,似乎找不到操作文档。当我检查文档数据库中字段的值时,我看到的只是空值。我正在使用位数组上传文件。 这是我的代码

控制器

public ActionResult Dokument()
    {
        return View();
    }

    public ActionResult GetTipi()
    {
        Test_kristiEntities1 db = new Test_kristiEntities1();
        return Json(db.AAC_procedure_document_types.Select(x => new
        {
            Id_Tipi = x.Id_Tipi,Emri_llojit = x.Emri_llojit
        }).ToList(),JsonRequestBehavior.AllowGet);
    }


    // Bind(Include = "Nr_Kutise,Rafti,Zyra,")]Ngarkodokument ngarkodok

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Create(HttpPostedFileBase upload,AAC_procedure_document_types model,Ngarkodokument ngarkodok,AAC_procedure_documents dokumente)
    {
        try
        {
            if (ModelState.IsValid)
            {
                if (upload != null && upload.ContentLength > 0)
                {
                    var file = new AAC_procedure_documents
                    {
                        Emer_Dokumenti = System.IO.Path.GetFileName(upload.FileName),//FileType = FileType.Avatar,Content_Type = upload.ContentType
                    };
                    using (var reader = new System.IO.BinaryReader(upload.InputStream))
                    {
                        file.Permbajtje_Dokumenti = reader.ReadBytes(upload.ContentLength);
                    }
                    ngarkodok.AAC_procedure_documents = new List<AAC_procedure_documents> { file };
                }

                ViewData["Rafti"] = dokumente.Rafti;
                ViewData["Zyra"] = dokumente.Zyra;
                ViewData["Nr_Kutise"] = dokumente.Nr_Kutise;

               // lokacion.Rafti = formCollection["Rafti"].ToString();
               // lokacion.Zyra = formCollection["Zyra"].ToString();
               // lokacion.Nr_Kutise = Convert.ToInt32(formCollection["Nr_Kutise"]);

                db.AAC_procedure_documents.Add(dokumente);
                db.SaveChanges();
                return RedirectToAction("Dokument");
            }
        }
        catch (RetryLimitExceededException /* dex */)
        {
            //Log the error (uncomment dex variable name and add a line here to write a log.
            ModelState.AddModelError("","Unable to save changes. Try again,and if the problem persists see your system administrator.");
        }
        return View(dokumente);
    }

HTML格式

<div id="myModal" class="modal fade" role="dialog">
    <div class="modal-dialog">

<!-- Modal content-->
<div class="modal-content">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Ngarkoni dokumenta</h4>
    </div>
    <div class="modal-body">
        @using (Html.BeginForm("Create","Ngarkodokument",FormMethod.Post,new { enctype = "mulptiple/form-data" }))
        {
            @Html.AntiForgeryToken()

            <div class="form-group">
                <label for="exampleFormControlSelect1">Lloji i dokumentit</label><br />
                <select title="Lloji i dokumentit" name="lloji" class="form-control col-md-3 Box" id="tipiDropdown"> </select>


                <input type="button" title="Ngarko dokument" name="ngarko" value="Ngarko" id="uploadPop" class="btn btn-info col-md-3" onclick="document.getElementById('file').click();" />
                <input type="file" onchange="javascript: updateList()" multiple="multiple" style="display:none;" id="file" name="postedFiles" />
                <div id="fileList"></div>
            </div>
            <br /><br />

            <div class="form-group">
                <label for="formGroupExampleInput">Fusha indeksimi</label> <br />
                @*<input title="Indeksimi dokumentit" id="indeksimi" class="form-control col-md-3" type="text" name="indeksimi" placeholder="indeksimi" required />*@
                @Html.TextBoxFor(a => a.Fusha_Indeksimit.Emri_Indeksimit,new { @class = "form-control",@placeholder = "indeksimi" })

                <button title="Shto indeksim" id="modalPlus" type="submit" class="btn btn-info"><i class="glyphicon glyphicon-plus"></i></button>


            </div>

            <label for="formGroupExampleInput">vendndodhja fizike e dokumentit</label><br>
            <div id="zyraModal" class="form-group col-md-4">
                @*<input title="Zyra fizike" id="zyra" class="form-control" type="text" name="zyra" placeholder="Zyra" />*@
                @Html.TextBoxFor(a => a.vendndodhja_fizike.Zyra,@placeholder = "Zyra" })
            </div>

            <div class="form-group col-md-4">
                @* <input title="Kutia fizike" id="kutia" class="form-control" type="number" name="kutia" placeholder="Nr i kutisë" />*@
                @Html.TextBoxFor(a => a.vendndodhja_fizike.Nr_Kutise,@placeholder = "Nr i kutisë" })
            </div>

            <div class="form-group col-md-4">
                @* <input title="Rafti fizik" id="rafti" class="form-control" type="text" name="rafti" placeholder="Rafti" />*@
                @Html.TextBoxFor(a => a.vendndodhja_fizike.Rafti,@placeholder = "Rafti" })
            </div>

            <br /><br />

            <div class="row" id="ruaj">
                <button value="Create" title="Ruaj dokumentin" type="submit" class="btn btn-success">Ruaj</button>
            </div>
        }
    </div>
</div>

这是我的路线配置

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",url: "{controller}/{action}/{id}",defaults: new { controller = "Home",action = "Login",id = UrlParameter.Optional }
            );

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)