0

您好,我正在尝试根据 MVC 音乐商店教程在我的 MVC 电子商务网站上使用贝宝按钮。我正在从数据库中加载特定数据,因此我希望在我的网站中为每个类别提供一个带有下拉菜单的按钮。我想知道如何在教科书类别启动时隐藏一个按钮,并在固定类别启动时再次显示它,因此我只有在任何时候都可以看到该类别的特定按钮。所以基本上当视图指向浏览教科书类别时,我只希望教科书按钮可见。我的代码如下

存储控制器:

  public ActionResult Browse(string category)
    {
        // Retrieve Category and its Associated Products from database
        var categoryModel = storeDB.Categories.Include("Products")
        .Single(c => c.Name == category);

        return View(categoryModel);


    }

浏览视图:

@model WholeschoolStore3.Models.Category

@{
ViewBag.Title = "Browse Categorys";
}

<div class="product">
<h3><em>@Model.Name</em> Products</h3>

<ul id="Product-list">
    @foreach (var product in Model.Products)
    {
        <li>
            <a href="@Url.Action("Details", new { id = product.ProductId })">
                <img alt="@product.ProductName" src="@product.ProductUrl" />
                <span>@product.ProductName</span>
            </a>
        </li>
    }
</ul>                                                                                                                                                                                                      
<form target="paypal" action="" method="post">
<input type="hidden" name="cmd" value="_s-xclick"/>
<input type="hidden" name="hosted_button_id" value=""/>
School Books<select name="os0">
<option value="History Book">History Book €38.99 EUR</option>
<option value="Biology Book">Biology Book €34.99 EUR</option>
<option value="Math Book">Math Book €39.99 EUR</option>
<option value="Geography Book">Geography Book €34.99 EUR</option>
<option value="Business Studies Book">Business Studies Book €37.99 EUR</option>
</select>
<input type="hidden" name="currency_code" value="EUR"/>
<input type="image" src=""  
 width="1" height="1"/>
<img alt="" border="0" src=""    
 width="1" height="1"/>


</form>
<form target="paypal" action="" method="post">
<input type="hidden" name="cmd" value="_s-xclick"/>
<input type="hidden" name="hosted_button_id" value=""/>
<input type="hidden" name="on0" value="Stationary"/>Stationary<select name="os0">
<option value="Pencil">Pencil €0.49 EUR</option>
<option value="Pen">Pen €0.89 EUR</option>
<option value="A4 Refill pad">A4 Refill pad €3.99 EUR</option>
</select> 
<input type="hidden" name="currency_code" value="EUR"/>
<input type="image" src=""
border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"/>      
<img alt="" border="0" src=""  
 width="1" height="1"/>
</form>



</div>

我尝试了许多帖子,但没有找到我要找的东西

任何帮助将不胜感激提前谢谢

4

2 回答 2

0

You can achieve it using jquery/javascript. On the basis of option selected you can hide and show any button you want .

Please refer the example. In this example button will hide if you select the option Pen €0.89 EUR in rest of the cases it will show

        <!DOCTYPE html>
        <html>
        <head>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
        </script>
        <script>
        $(document).ready(function(){

        $("select").change(function () {
          $("select option:selected").each(function () {
                if ($(this).text()=='Pen €0.89 EUR' )
                   $("#btnGo").hide();
                else
                   $("#btnGo").show();
              });
        })
        .trigger('change');
        });
        </script>
        </head>
        <body>

        <select name="os0">
        <option value="Pencil">Pencil €0.49 EUR</option>
        <option value="Pen">Pen €0.89 EUR</option>
        <option value="A4 Refill pad">A4 Refill pad €3.99 EUR</option>
        </select> 
        <input id="btnGo" type="button" value="Hi" />
        </body>
        </html>

Also your html has some problem first select is closed before the option is begin it should be like

School Books<select name="os0">
<option value="History Book">History Book €38.99 EUR</option>
<option value="Biology Book">Biology Book €34.99 EUR</option>
<option value="Math Book">Math Book €39.99 EUR</option>
<option value="Geography Book">Geography Book €34.99 EUR</option>
<option value="Business Studies Book">Business Studies Book €37.99 EUR</option>
</select>
于 2013-05-27T11:23:00.107 回答
0

我找到了一种解决问题的方法,我刚刚添加了一个 div,然后将其隐藏,然后添加了一个复选框,单击该复选框时会显示 div,代码如下:

 <script  type="text/javascript">
         $(function () {
             $('#ShowHideMe').hide();
             $('#myCheckbox').change(function () {
                 $('#ShowHideMe').toggle($(this).is(':checked'));
             });
         });
</script>

     <input type="checkbox" id="myCheckbox"/>SchoolBooks
<div id="ShowHideMe">                                                                                                                                                                                                    
   //form code here
</div>    
<br />

   <script  type="text/javascript">
       $(function () {
           $('#ShowHideMe1').hide();
           $('#myCheckbox1').change(function () {
               $('#ShowHideMe1').toggle($(this).is(':checked'));
           });
       });
 </script>

     <input type="checkbox" id="myCheckbox1"/>Stationary
 <div id="ShowHideMe1">
      //form code here
 </div>

感谢任何回复的人的帮助

顺便说一句,我丢失了另一个帐户的密码,所以不得不创建一个新帐户,这就是为什么我以其他用户身份回复

于 2013-06-04T12:52:54.623 回答