I am newbie in asp.net mvc. I have 2 cascading dropdownlist and 1 file input on my page. I made cascading dropdownlists following this tutorial. But when I trying to pass value to controller, there is an error System.ArgumentException, null parameter. I looked up the list of parameters using Firebug, but I can't find value of second dropdown at all.

My controller code is below:

       public ActionResult Index()
    {

        List<SelectListItem> branchNames = new List<SelectListItem>();
        FormatModel fmtModel = new FormatModel();

        List<branch> branches = db.branch.ToList();


        branches.ForEach(x =>
        {
            branchNames.Add(new SelectListItem { Text = x.name, Value = x.id.ToString() });
        }
        );
        fmtModel.BranchNames = branchNames;
        return View(fmtModel);


    }

    [HttpPost]
    public ActionResult GetPaymentSystem(string branchId)
    {
        int intBranchId;

        List<SelectListItem> paymentSystemNames = new List<SelectListItem>();
        if (!string.IsNullOrEmpty(branchId))
        {
            intBranchId = Convert.ToInt32(branchId);

            List<paymentSysDTO> paymentSystems =
            (from ps in db.paymentSys
             join ps_br in db.br_ps_format on ps.id equals ps_br.ps_id
             join br in db.branch on ps_br.branch_id equals br.id
             where br.id == intBranchId
             select new paymentSysDTO
             {
                 id = ps.id,
                 name = ps.name,
                 code = ps.code
             }
            ).ToList();

            paymentSystems.ForEach(x =>
            {
                paymentSystemNames.Add(new SelectListItem { Text = x.name, Value = x.id.ToString() });
            }
               );
        }
        return Json(paymentSystemNames, JsonRequestBehavior.AllowGet);
    }

    [HttpPost]
    public ActionResult Index(int BranchNames, int PaymentSystemNames, HttpPostedFileBase file)
    {
      //controller code
    }

View code:

 @using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
 {
        <legend>Введите данные:</legend>
        <table>
            <tr>
                <td>
                    <label>Филиал</label>
                </td>
                <td>
                    @Html.DropDownListFor(x => x.BranchNames, Model.BranchNames, "Выбрать", new { id = "ddlBranch" })
                </td>
            </tr>
            <tr>
                <td>
                    <label>Платежная система/Банк</label>
                </td>
                <td id="PaymentSystem">
                    @Html.DropDownListFor(x => x.PaymentSystemNames, new List<SelectListItem>(), "Выбрать", new { @id = "ddlPaymentSystem" })
                </td>
            </tr>
            <tr>
                <td>
                    <input id="InputFile" type="file" name="file" />
                </td>
            </tr>
            <tr>
                <td>
                    <input id="ConvertButton" type="submit" value="Конвертировать" />
                </td>
            </tr>
            </table>
}
        @if (null != TempData["msg"])
{
            @Html.Raw(TempData["msg"])
}

<script type="text/javascript">
    $(function () {
        $('#ddlBranch').change(function () {
            $.ajax({
                type: 'POST',
                url: "/Home/GetPaymentSystem",
                data: { branchID: $('#ddlBranch').val() },
                datatype: "json",
                traditional: true,
                success: function (data) {
                    var paymentSystem = "<select id='ddlPaymentSystem'>";
                    paymentSystem = paymentSystem + '<option value ="">Select</option>';
                    for (var i = 0; i < data.length; i++)
                    {
                        paymentSystem = paymentSystem + '<option value=' + data[i].Value + '>' + data[i].Text + '</option>';
                    }
                    paymentSystem = paymentSystem + '</select>';
                    $('#PaymentSystem').html(paymentSystem);
                }
                cas
            });
        });
    });
</script>

Sorry for my English and thanks for ur help.

Related posts

Recent Viewed