无法将 System.Windows.Forms.Form 隐式转换为 'String'

Can not implicitly convert System.Windows.Forms.Form to 'String'

嘿,我有一个模式弹出窗体,我必须在其中将文件和 post 数据上传到数据库。在控制器中,我通过 FormCollection 检索值。当我尝试使用表单集合获取输入字段时出现此错误:无法将 System.Windows.Forms.Form 隐式转换为 'String'。这是我的代码:

控制器

 [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(FormCollection formCollection, HttpPostedFileBase upload, AAC_procedure_document_types model,NgarkoDokument ngarkoDok)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (upload != null && upload.ContentLength > 0)
                    {
                        var file = new AAC_procedure_documents
                        {
                            Emer_Dokumenti = System.IO.Path.GetFileName(upload.FileName),
                            Lloji_File = model.Emri_llojit,
                            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 };
                    }

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

                    db.AAC_procedure_documents_location.Add(lokacion);
                    db.SaveChanges();
                    return RedirectToAction("Dokumenti");
                }
            }
            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(formCollection);
        }

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, new { @class = "form-control", @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, new { @class = "form-control", @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, new { @class = "form-control", @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>

FormCollection 的命名空间必须是 System.Web.Mvc 而不是 System.Windows.Forms。查看您的使用并删除 System.Windows.Forms...

class FormCollection 存在于两种技术中,WindowsForm 和 Web。