0

嗨,人们在 MVC3 中遇到问题,我的 jquery 滑块在我需要滑块的地方显示以下错误:

[object Object]

滑块不可见,我添加的 jquery 脚本如下:

<script type="text/javascript">

    $(function () {
        $("#slider-range-max").slider({
            range: "max",
            min: 1,
            max: 10,
            value: 2,
            slide: function (event, ui) {
                $("#Score").val(ui.value);
            }
        });
        $("#Score").val($("#slider-range-max").slider("value"));
    });
    </script>

在我看来,它指的是这个领域:

 <div class="editor-label">
        @Html.LabelFor(model => model.Score)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Score)
        @Html.ValidationMessageFor(model => model.Score)
    </div>

我已将以下 jquery 脚本添加到我的视图中:

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"</script>
<link href="../../Content/themes/base/jquery.ui.all.css" rel="stylesheet" type="text/css"/>
<script src="../../Scripts/jquery-ui-1.8.11.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.ui.core.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.ui.widget.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.ui.slider.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.ui.mouse.js" type="text/javascript"></script>
<script src="../../Scripts/modernizr-1.7.js" type="text/javascript"></script>

如果您需要其他信息,请询问我,谢谢

4

1 回答 1

1

首先,您需要添加以下 jquery 脚本:

<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css" type="text/css" media="all" />
<link rel="stylesheet" href="http://static.jquery.com/ui/css/demo-docs-theme/ui.theme.css" type="text/css" media="all" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js" type="text/javascript"></script>
<script src="http://jquery-ui.googlecode.com/svn/tags/latest/external/jquery.bgiframe-2.1.2.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/i18n/jquery-ui-i18n.min.js" type="text/javascript"></script>

其次将此添加到您的视图中:

<script type="text/javascript">
    $(function() {
        $( "#slider-range-max" ).slider({
            range: "max",
            min: 1,
            max: 10,
            value: 2,
            slide: function( event, ui ) {
                $("#PutYourValueHere").val(ui.value);
            }
        });
$("#PutYourValueHere").val($("#slider-range-max").slider("value"));
    });
    </script>

上面显示的 PutYourValueHere 与 model.PutValueHere 相对应。

  @Html.EditorFor(model => model.PutYourValueHere)

按照这些步骤应该可以工作。

于 2012-04-11T00:17:37.273 回答