我的代码在Partial View(ascx)中不起作用?

时间:2011-06-28 05:39:24

标签: asp.net-mvc

我的代码是:

<script type="text/javascript">
     $(document).ready(function () {
         alert("dd");
         //Attach cascading behavior to the orderID select element.
         $("#orderID").CascadingDropDown("#customerID", '/Home/AsyncOrders',
            {
                promptText: '-- Pick an Order--',
                onLoading: function () {
                    $(this).css("background-color", "#ff3");
                },
                onLoaded: function () {
                    $(this).animate({ backgroundColor: '#ffffff' }, 300);
                }
            });

         //Attach cascading behavior to the orderDetails select element.
         $("#orderDetails").CascadingDropDown("#orderID", '/Sales/AsyncOrderDetails',
            {
                promptText: '-- Pick an Order Detail --',
                onLoading: function () {
                    $(this).css("background-color", "#ff3");
                },
                onLoaded: function () {
                    $(this).animate({ backgroundColor: '#ffffff' }, 300);

                }
            });

         //When an order detail is selected, fetch the details using ajax
         //and display inside a div tag.
         $('#orderDetails').change(function () {
             if ($(this).val() != '') {
                 $.post('/Sales/OrderDetails', $(this).serialize(), function (data) {
                     $('#orderDetailsContainer').html(data).effect("highlight", {}, 3000);
                 });
             }
         });
     });
    </script>

      <div id="searchFilter">
        Custom text in select lists, lists highlight when loading.<br />
        <%:Html.DropDownList("customerID", Model, "-- Select Customer --")%>
         <%--   <%:Html.DropDownList("cites", ViewData["xml"] as SelectList , "-- Select Customer --")%>--%>
        <select id="orderID" name="orderID">
        </select>
        <select id="orderDetails" name="orderDetails">
        </select>
    </div>
    <div id="orderDetailsContainer">
    </div>

当它在页面(aspx)中写入时非常神运行

但是当使用Partial View(ascx)时不运行代码?

1 个答案:

答案 0 :(得分:0)

确保你这样做

<% Html.RenderPartial("YourUserControl"); %>

或(注意冒号(:))

<%: Html.Partial("YourUserControl"); %>

或者您的部分视图不会写入文档