当我每次方法的参数具有相同的值时,使用ajax调用调用控制器方法

时间:2018-04-10 09:53:44

标签: ajax parameter-passing call onchange dropdown

我的观点如下:

<div class="form-group">
    @Html.LabelFor(model => model.ProductColorId, "Select Color", new { @class = "col-lg-2 control-label required-field" })
    <div class="col-lg-3">
        @Html.DropDownListFor(model => model.ProductColorId, new SelectList(ViewBag.Color, "ProductColorId", "ProductColor"), new { @class = "form-control col-lg-5 ", @id = "ddProductColor" })
        @Html.ValidationMessageFor(m => m.ProductColorId)
    </div>
    <br />
</div><br />
<div class="form-group">
    @Html.LabelFor(model => model.CompanyId, "Select Company", new { @class = "col-lg-2 control-label required-field" })
    <div class="col-lg-3">
        @Html.DropDownListFor(model => model.CompanyId, new SelectList(ViewBag.Company, "CompanyId", "CompanyName"), new { @class = "form-control  selectpicker", @id = "ddCompany" })
        @Html.ValidationMessageFor(m => m.CompanyId)
    </div>

</div>

我正在尝试获取下拉列表中所选选项的ID,并希望将其发送到控制器方法。 我的ajax调用JS正在关注:

<script type="text/javascript">

$(document).ready(function () {

    customerId = 5;

    colorId = $("#ddProductColor option:selected").val();
    companyId = $("#ddCompany option:selected").val();
    initializeProductFile();
});

function initializeProductFile() {
    $form = $('#productfileupload').fileupload({
        dataType: 'json',
        formData: { customerId: customerId, colorId: colorId, companyId: companyId}
    });
    debugger;
    $("[name=jobId]").val(customerId);
    $.ajax({

        type: 'GET',
        contentType: "application/json;charset=utf-8",
        url: '/LooksFile/GetFileList',
        data: { customerId: customerId, colorId: colorId, companyId: companyId},
        success: function (data) {
            $('#productfileupload').fileupload('option', 'done').call($('#productfileupload'), $.Event('done'), { result: { files: data.files } })
            $('#productfileupload').removeClass('fileupload-processing');
        }
    });
    $('#productfileupload').addClass('fileupload-processing');

}

我的控制器方法如下:

public JsonResult Upload(int customerId, int? colorId, int companyId)

你的小帮助可以让我高兴。谢谢你。

0 个答案:

没有答案