0

こんにちは、私は私の見解で次のコードを持っています:

@model Test.tblReview

@{
    ViewBag.Title = "Create";
}

<div class = "under">
Add a New Review
</div>

<br />

<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>
<link href="../../Content/themes/base/jquery.ui.slider.css" rel="stylesheet" type="text/css" />

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)


        <div class="editor-label">
            @Html.HiddenFor(model => model.ReviewID)
        </div>

        <div class="editor-field">
            @Html.HiddenFor(model => model.ReviewID)
            @Html.HiddenFor(model => model.ReviewID)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Recomendation)
        </div>


        <div class="editor-field">
            @Html.TextAreaFor(model => model.Recomendation, new { style = "max-width: 200px; max-height: 150px;" })
            @Html.ValidationMessageFor(model => model.Recomendation)
        </div>

    <br />


        <div class="editor-label">
            @Html.LabelFor(model => model.AvoidOrBuy)
        </div>



        <div class="editor-field">
            @Html.TextAreaFor(model => model.AvoidOrBuy, new { style = "max-width: 200px; max-height: 150px;" })
            @Html.ValidationMessageFor(model => model.AvoidOrBuy)
        </div>

        <br />

         <div class="editor-label">
          @*@Html.LabelFor(model => model.Posted)*@
        </div>

        <div class="editor-field">
            @Html.HiddenFor(m => m.Posted)
            @Html.ValidationMessageFor(model => model.Posted)
        </div>

        <br />

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

     <br />

        <div class="demo" style="width: 185px">
        <div id="slider-range-max"></div>
        </div>

    <br />

       <p>Score Added From Scroll Bar</p>

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

     <br />
        <div class="editor-label">
            @Html.LabelFor(model => model.GameIDFK, "tblGame")
        </div>



        <div class="editor-field">
            @Html.DropDownList("GameIDFK", String.Empty)
            @Html.ValidationMessageFor(model => model.GameIDFK)
        </div>

        <div class="editor-label">
            @Html.HiddenFor(model => model.UserName)
        </div>

        <div class="editor-field">
            @Html.HiddenFor(model => model.UserName)
            @Html.HiddenFor(model => model.UserName)
        </div>

     <br />

        <p>
            <input type="submit" value="Create" />
        </p>

}

<div>
    @Html.ActionLink("Go To Reviews", "Index") |  @Html.ActionLink("Go Back To Games", "Index", "Game")
</div>

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

すべて正常に動作しますが、ドロップダウンの値を選択して送信ボタンを押したら、ドロップダウンの値をクリアしたいと思います。追加情報が必要な場合は、お問い合わせください。

4

1 に答える 1

1

ドロップダウンの値が選択され、送信ボタンが押されるとクリアされます

なぜこれを行う必要があるのですか?今後の処理のために値を読み取るアクションメソッドに値を送信する場合は、値を変更すべきではないと強く信じています。選択した値をそこで取得するつもりはないからです。選択した値が気にならない場合は、次のように jQuery でクリアできます

$(function(){
 $("form").submit(function(){
   $("#GameIDFK").empty();
   return true;
 });
});

私の頭に浮かんだもう1つのことは、本当にドロップダウンをクリアしたいが、まだアクションメソッドで使用している場合は、おそらくフォームに非表示の入力要素が必要であり、Javaスクリプトを使用して、選択した値を設定できるということですそこにドロップダウンします。次に、ドロップダウンをクリアしてから、アクションメソッドで、実際のドロップダウンではなく非表示の入力から読み取ることができます。

于 2012-04-16T03:11:36.793 に答える