Can not implicitly convert System.Windows.Forms.Form to ‘String’

Hey so I have a modal popup form where I have to upload files and post data to the database. In the controller I’m retrieving the values by FormCollection. When I try to get the input fields with form collection i get this error : Can not implicitly convert System.Windows.Forms.Form to ‘String’. Here is my code:


        public ActionResult Create(FormCollection formCollection, HttpPostedFileBase upload, AAC_procedure_document_types model,NgarkoDokument ngarkoDok)
                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"]);

                    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 form
<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 class="modal-body">
                @using (Html.BeginForm("Create", "NgarkoDokument", FormMethod.Post, new { enctype = "mulptiple/form-data" }))

                    <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>
                    <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>


                    <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 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 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" })

                    <br /><br />

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


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

The namespace to FormCollection must to be System.Web.Mvc instead of System.Windows.Forms. Take a look in your usings and remove System.Windows.Forms…

The class FormCollection exists in two tecnologies, WindowsForm and Web.

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x