0

I am having an issue that when I am calling a function to transfer data file and Parameters. alert() is showing data but it is not transferring to the controller .Controller showing null values

Jquery

 $(".UpdateClientInfomationOutCome").click(function () {
        debugger;
        alert("Test");



        var formData = new FormData($("#fileupload")[0]);
        var collectFacilityNam = $("#Collect_Facility_Name").val();
        var locationProviderNam = $("#Location_Provider_Name").val();
        var locationProviderAddres = $("#Location_Provider_Address").val();

        $.ajax({
            url: '@Url.Action("ClientInformatioUpdate", "OutCome")',
            type: 'POST',
            data: { doc: formData, collectFacilityName: collectFacilityNam, locationProviderName: locationProviderNam, locationProviderAddress: locationProviderAddres },
            cache: false,
            contentType: false,
            processData: false,
            async: false,
            success: function (data) {

            }
        });

    });

Controller

[HttpPost]
    public ActionResult ClientInformatioUpdate(FormCollection collection,string collectFacilityName, string locationProviderName, string locationProviderAddress, HttpPostedFileBase doc)
    {

        return View();
    }

Html

<form method="post" enctype="multipart/form-data">
    <div class="container" style="width: 90%">
        <fieldset>
            <legend style="font-size: large; text-align: center"> Add Client Information</legend>
            <input class="text-box single-line" id="Collect_Facility_Name" name="Collect_Facility_Name" type="text" value="" placeholder="Collect Facility Name">
            <input class="text-box single-line" id="Location_Provider_Name" name="Location_Provider_Name" type="text" value="" placeholder="Location Provider Name">
            <input class="text-box single-line" id="Location_Provider_Address" name="Location_Provider_Address" type="text" value="" placeholder="Location Provider Address">
            <input style="display: none" name="AlreadyinCare" type="text" value="AlreadyinCare">
            <input type="file" name="doc" id="fileupload" multiple="" placeholder="Upload Document">
           <br>
            <input name="file" type="text">
        </fieldset>

        <input type="hidden" name="form_type" value="NeverinCare">
        <div style="float: right;">

            <input type="button" class="UpdateClientInfomationOutCome" value="Add">



        </div>
</form>
ZCoder
  • 2,155
  • 5
  • 25
  • 62
  • Define a single model (called a view model) with all the properties on it and then have that in your action signature, `public ActionResult ClientInformatioUpdate(MyViewModel viewModel)` – nurdyguy Oct 19 '17 at 21:01
  • I was using Custom ViewModel was not working so i jump to parameters – ZCoder Oct 19 '17 at 21:03
  • 3
    You cannot combine `FormData` and objects - you need to `.append()` the other data to your `FormData` object –  Oct 19 '17 at 21:04
  • https://stackoverflow.com/questions/29293637/how-to-append-whole-set-of-model-to-formdata-and-obtain-it-in-mvc – ZCoder Oct 20 '17 at 19:25

0 Answers0