这哪里是" String中太多字符文字"从消息来? [英] Where is this "Too Many Characters in String literal" message coming from?

查看:90
本文介绍了这哪里是" String中太多字符文字"从消息来?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上都好,

我敢肯定,这是给我,但我不知道在哪里这个问题的来源。

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

我有一个观点以下行:

<fieldset>
    <dl>
        <dt>
            <label for="FormTypes">Form Type:</label>
        </dt>
        <dd>           
            <% =Html.DropDownList("FormTypes", "All") %>
        </dd>
    </dl>
</fieldset>
<fieldset>
    <dl>
        <dt>
            <label for="Parts">Form Part:</label>
        </dt>
        <dd>           
            <% =Html.DropDownList("Parts", "All") %>
        </dd>
    </dl>
</fieldset>

这不会引起问题,但添加下面的脚本基于表单类型的选择,以更新零件顶部时(以下这个问题的答案SO质疑<一个href=\"http://stackoverflow.com/questions/1585642/bind-dropdownlists-with-jquery-in-asp-net\">http://stackoverflow.com/questions/1585642/bind-dropdownlists-with-jquery-in-asp-net)

This causes no problems, but when adding the following script to the top of to update Parts based on the selection of form type (following the answer to this SO question http://stackoverflow.com/questions/1585642/bind-dropdownlists-with-jquery-in-asp-net)

<script type="text/javascript">
    <!--
        $('#FormTypes').change(function() {
            var val = $(this).val();
            $parts = $('#Parts');
            $.ajax({
                url: '<%= Url.Action('FormParts') %>',
                dataType: 'json',
                data: { ID: val },
                success: function(parts) {
                    $.each(parts, function(i, part) {
                        $parts.append('option value="' + part.ID+ '">' + part.Code + '</option>');
                    });
                },
                error: function() {
                    alert('Failed to retrieve parts list.');
                }
            });
        });

    //-->
</script>

(其中FormParts操作将返回一个新的对象来填充零件下拉列表)

(where the FormParts action will return a new object to populate the parts drop down list)

我得到的消息:字符字符太多文字的就行了。

I get the message: Too many characters in character literal on the line

<% =Html.DropDownList("Types") %>

看来这个问题是由JavaScript引起的被加入,但为什么,为什么误差在$ P $在标记code的pviously好的路线,而不是在脚本?

It appears this issue is caused by the javascript being added, but why and why the error is on the previously good line of code in the markup and not in the script?

先谢谢了。

推荐答案

我不知道在哪里这个问题是从,我已经更新脚本下面来和它的作品。

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>

有关使用该code,在未来的任何人,请注意我已经添加了评估

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

if (selectedValue != "")

如果全部,在第一FormTypes选择了这个选项已经添加下拉列表中,有应填充,没有相关的部分名单。

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.

这篇关于这哪里是&QUOT; String中太多字符文字&QUOT;从消息来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆