Where is this “Too Many Characters in String literal” message coming from?

后端 未结 2 1413
灰色年华
灰色年华 2020-12-22 05:13

Good morning all,

I\'m sure this is a gimme, but I have no idea where this issue is coming from.

I have the following lines in a view:



        
相关标签:
2条回答
  • 2020-12-22 05:27

    I'm not sure where that issue was coming from, I've updated the script to the following and it works.

    <script type="text/javascript">
        <!--
    
        $(function() {
            $('#FormTypes').change(function() {
                //clear all items in list and replace "All" option
                $parts = $('#FormParts');
                $parts.html("");
                $parts.append('<option value="">All</option>');
    
                var selectedValue = $(this).val();
                if (selectedValue != "") {
                    $.ajax({
                        url: '<%= Url.Action("FormParts") %>',
                        dataType: 'json',
                        data: { FormTypeID: selectedValue },
                        success: function(parts) {
                            //repopulate list with JSON objects
                            $.each(parts, function(i, part) {
                                $parts.append('<option value="' + part.ID + '">' + part.Code + '</option>');
                            });
                        },
                        error: function() {
                            alert('Parts list could not be retreived. \n Please use the feedback link to inform us');
                        }
                    });
                }
            });
        });
        //-->
    </script>
    

    For anyone using this code, in future, please note I've added the evaluation

    if (selectedValue != "")
    

    this has been added if the option "All" is selected in the first FormTypes drop down list, there is no dependent part list that should be populated.

    0 讨论(0)
  • 2020-12-22 05:39

    While there's nothing wrong with the line you seperated out, this part in the original code does bother me:

    <%= Url.Action('FormParts') %>
    

    You used single quotes for the string in ASP. This marks it as a character literal, and not a string. Replace them with double quotes and you should be fine.

    <%= Url.Action("FormParts") %>
    
    0 讨论(0)
提交回复
热议问题