Advertisement
PanuSy

IndexView

Feb 26th, 2020
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 4.68 KB | None | 0 0
  1. @model IEnumerable<NorthwindData.Models.Customers>
  2.  
  3. @section scripts {
  4.     <script src="~/Scripts/jquery-1.10.2.js"></script>
  5.     <script type="text/javascript">
  6.         $(function () {
  7.  
  8.             var openMode = $(this).hasClass("glyphicon-plus");
  9.             if (openMode === true) {
  10.                 //load order for this customer.
  11.                 $(".näytäTilauksetNappi").click(function () {
  12.                     alert("Nappia painettu!");
  13.                     var customerId = $(this).data("customerid");
  14.                     //alert(customerId);
  15.                     $("#orders_" + customerId).css("display", "block");
  16.                     var url = "/customer/getorders/" + customerId;
  17.                     $.ajax(url).done(function (data) {
  18.                         //alert("Palvelimelta tuli vastaus.");
  19.  
  20.                         var orderData = "";
  21.                         for (var i = 0; i < data.length; i++) {
  22.                            orderData += (i + 1) + ": " + data[i].OrderId + " " +
  23.                                data[i].OrderDate + " " + data[i].CustomerId + "\r\n";
  24.                        }
  25.                        $("#orderText_" + customerId).html("<pre>" + orderData + "</pre>");
  26.                         $(spanElement).removeClass("glyphicon-plus");
  27.                         $(spanElement).addClass("glyphicon-minus");
  28.                     });
  29.                 });
  30.             }
  31.             else {
  32.                 $(this).removeClass("glyphicon-minus");
  33.                 $(this).addClass("glyphicon-plus");
  34.                 var customerId = $(this).data("customerid");
  35.                 $("orders_" + customerId).css("display", "none");
  36.             }
  37.         });
  38.     </script>
  39. }
  40.  
  41. <h2>Index</h2>
  42.  
  43. <pre>
  44. @ViewBag.ErrorMessage
  45. </pre>
  46.  
  47. <p>
  48.     @Html.ActionLink("Create New", "Create")
  49. </p>
  50. <table class="table">
  51.     <tr>
  52.         <th>
  53.             @Html.DisplayNameFor(model => model.CustomerID)
  54.         </th>
  55.         <th>
  56.             @Html.DisplayNameFor(model => model.CompanyName)
  57.         </th>
  58.         <th>
  59.             @Html.DisplayNameFor(model => model.ContactName)
  60.         </th>
  61.         <th>
  62.             @Html.DisplayNameFor(model => model.ContactTitle)
  63.         </th>
  64.         <th>
  65.             @Html.DisplayNameFor(model => model.Address)
  66.         </th>
  67.         <th>
  68.             @Html.DisplayNameFor(model => model.City)
  69.         </th>
  70.         <th>
  71.             @Html.DisplayNameFor(model => model.Region)
  72.         </th>
  73.         <th>
  74.             @Html.DisplayNameFor(model => model.PostalCode)
  75.         </th>
  76.         <th>
  77.             @Html.DisplayNameFor(model => model.Country)
  78.         </th>
  79.         <th>
  80.             @Html.DisplayNameFor(model => model.Phone)
  81.         </th>
  82.         <th>
  83.             @Html.DisplayNameFor(model => model.Fax)
  84.         </th>
  85.         <th></th>
  86.     </tr>
  87.  
  88.     @foreach (var item in Model)
  89.     {
  90.         <tr>
  91.             <td>
  92.                 <a href="#"><span data-customerid="@Html.DisplayFor(modelItem => item.CustomerID)" class="glyphicon glyphicon-plus näytäTilauksetNappi"></span></a>
  93.                 @Html.DisplayFor(modelItem => item.CustomerID)
  94.             </td>
  95.             <td>
  96.                 @Html.DisplayFor(modelItem => item.CompanyName)
  97.             </td>
  98.             <td>
  99.                 @Html.DisplayFor(modelItem => item.ContactName)
  100.             </td>
  101.             <td>
  102.                 @Html.DisplayFor(modelItem => item.ContactTitle)
  103.             </td>
  104.             <td>
  105.                 @Html.DisplayFor(modelItem => item.Address)
  106.             </td>
  107.             <td>
  108.                 @Html.DisplayFor(modelItem => item.City)
  109.             </td>
  110.             <td>
  111.                 @Html.DisplayFor(modelItem => item.Region)
  112.             </td>
  113.             <td>
  114.                 @Html.DisplayFor(modelItem => item.PostalCode)
  115.             </td>
  116.             <td>
  117.                 @Html.DisplayFor(modelItem => item.Country)
  118.             </td>
  119.             <td>
  120.                 @Html.DisplayFor(modelItem => item.Phone)
  121.             </td>
  122.             <td>
  123.                 @Html.DisplayFor(modelItem => item.Fax)
  124.             </td>
  125.             <td>
  126.                 @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
  127.                 @Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
  128.                 @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
  129.             </td>
  130.         </tr>
  131.         <tr style="display: none;" id="orders_@Html.DisplayFor(modelItem => item.CustomerID)">
  132.             <td>&nbsp;</td>
  133.             <td colspan="5" id="orderText_@Html.DisplayFor(modelItem => item.CustomerID)"><pre>Loading...</pre></td>
  134.         </tr>
  135.     }
  136.  
  137. </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement