2012-04-16 45 views
0

嗨如何清除下拉列表中我有我的看法如下代码:一旦价值选择和submited

@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> 

一切工作正常,但我想办法让价值在下拉清除一旦它被选中并提交按钮被按下,如果您需要addtional信息请咨询我谢谢

回答

1

the value in the drop down to clear once its been selected and the submit button is pressed

你为什么要这么做?我坚信,如果您要将其提交给您要读取它进行进一步处理的操作方法,则不应更改此值。因为你不会在那里得到选定的价值。如果你不担心选择的值,那么你可以明确的是jQuery的这样

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

的另一件事情来到我的脑海的是,如果你真的想清除下拉,但仍在使用操作方法,您可能需要在窗体中使用隐藏的输入元素并使用java脚本,可以将所选的下拉列表的值设置为该值。然后在你可以清除你的下拉菜单,然后在你的操作方法中,你可以从隐藏的输入中读取,而不是实际的下拉菜单。

+0

请试试这个让你知道的信息谢谢你 – user1319420 2012-04-16 03:12:59

+0

我收到以下错误:更新条目时发生错误。详情请参阅内部例外。 – user1319420 2012-04-16 03:17:06

+0

我想这样做的原因是,我可以登录创建相同的游戏评论,所有准备好的评论都是为什么我想要在提交后清除信息 – user1319420 2012-04-16 03:17:56