通过jQuery AJAX发送的值在控制器中始终为null

时间:2019-05-20 09:22:15

标签: javascript jquery ajax asp.net-mvc

我很难用AJAX将在文本框中输入的字符串值传递给控制器​​。我已经尝试过了,但是没有用。

<div class="col-sm-3">
                            <label class="text-light-blue">MultiSelect Codes</label>
                            <div class="input-group">
                                <div class="input-group-addon">
                                    <i class="fa fa-globe"></i>
                                </div>
                                <select id="test" name="basic[]" multiple="multiple">
                                    <option value="1">1 Code</option>
                                    <option value="2">2 Code</option>
                                    <option value="3">3 Code</option>
                                    <option value="4">4 Code</option>
                                    <option value="70">70 Code </option>
                                    <option value="80">80 Code </option>
                                    <option value="90">90 Code </option>
                                    <option value="88">88 Code </option>
                                    <option value="99">99 Code </option>
                                </select>
                            </div>
                        </div>


                        <script>
                        $(function () {
                                    $('select[multiple]').multiselect({
                                        columns: 1,
                                        search: true,
                                        searchOptions: {
                                            showOptGroups: true,
                                            searchText: true,
                                            searchValue: true,
                                        },
                                        texts: {
                                            placeholder: 'Select Codes', search: 'Search',
                                            selectedOptions: ' selected',
                                            selectAll: 'Select all',
                                            unselectAll: 'Unselect all',
                                        },
                                        selectAll: true, // add select all option
                                        selectGroup: true, // select entire optgroup
                                        minHeight: 250,   // minimum height of option overlay
                                        maxHeight: 250,  // maximum height of option overlay
                                        maxWidth: 250,  // maximum width of option overlay (or selector)
                                        maxPlaceholderWidth: 250, // maximum width of placeholder button
                                        maxPlaceholderOpts: 250, // maximum number of placeholder options to show until "# selected" shown instead
                                        showCheckbox: true,  // display the checkbox to the user
                                        onOptionClick: function (element, option) { }, // fires when an option is clicked

                                    });
                                       });
                    </script>
<input type="text" name="refID" id="refID"><br />
<button type="button" class="submit">Submit</button>
$(document).ready(function() {
  $(".submit").click(function() {
    alert("hahaha");
    $.ajax({
      type: 'GET',
      url: '@Url.Action("TransactionVerification", "Dashboard")',
      data: {
        RefID: $("#refID").val()
      },
      success: function (response) {
        $(".content").html(response);
      },
      error: function () {
        alert("Problem on uploading file");
      }
    });
  });
});

当我调试控制器中的public async Task<ActionResult> TransactionVerification(String RefId) { //some code } 时,该值始终为空。

0 个答案:

没有答案