簡體   English   中英

ASP.NET MVC-如何顯示帶有arraylist數據的部分視圖

[英]ASP.NET MVC - How to show partial views with arraylist data

我想基於所選按鈕在aspx網頁上顯示三個不同的局部視圖。 那部分工作正常。 但是隨后,每個局部視圖將從xml文件讀取單獨的部分,並向視圖提供數據。 我試圖將數據作為Arraylist傳遞給視圖,但現在未顯示部分視圖。 如果不傳遞數據,則局部視圖有效。 請注意,我使用的是aspx而不是剃須刀。 關於如何進行此工作的任何構想,以便在單擊這三個按鈕中的任何一個時,也會顯示帶有xml數據的不同局部視圖。 提前致謝。

RenderVOIP.aspx

$(function() {
        $('#InfoButton').on("click", function() {        
            $.get('<%= Url.Action("InfoAction", "HardwareRequisition")%>', function (data) {
                $( "#myContentView" ).html( data );
            });
            $('#NotesButton').on("click", function() {              
                $.get('<%= Url.Action("NotesAction", "HardwareRequisition")%>', function (data) {
                    $( "#myContentView" ).html( data );
                });
                $('#OrdersButton').on("click", function() {                  
                    $.get('<%= Url.Action("OrdersAction", "HardwareRequisition")%>', function (data) {
                        $( "#myContentView" ).html( data );
                    });
                });
            });
        });
    });

<input type="text" id="box" style="width: 100px;" />
      <div class="row">
                    <div class="col-lg-12" id="account-subnavigation">
                        <div class="btn-group" style=" margin-bottom:10px; margin-left:10px;">                         
                            <button class="btn btn-info" style="width:120px" id="InfoButton">Info</button>
                            <button class="btn btn-info" style="width:120px" id="NotesButton">Notes</button>
                            <button class="btn btn-info" style="width:120px" id="ordersButton">Orders</button>
                        </div>
                    </div>
                </div>

               <div class="row" id="myContentView">

                </div>

voipSubform1.ascx

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Products>" %>

<h2>VoIP Subform 1</h2>
 test
<fieldset id="voipdetails" class="section2">

    <table class="table table-bordered"> 
<tr> 
<th>Id</th> 
<th>Product Name</th> 
<th>Product Cost</th> 
</tr> 
<% foreach (var product in ((IEnumerable<Products>)ViewData["data"]))

{ %> 
<tr> 
<td> 
    <%: product.ProductId%>
</td> 
<td> 
<%= product.ProductName%>
</td> 
<td> 
<%= product.ProductCost%>
</td> 
</tr> 
<% } %>
</table>
 
HardwareRequisitionController.cs

public ActionResult InfoAction()
            {
                //return View("VoIPSubform1", _repository.GetForm(8));
      //          return PartialView("_MySecondPartialView");
      //          return View("RenderVOIPForm", _repository.GetForm(8));

                var filename = AppDomain.CurrentDomain.BaseDirectory + "App_Data\\" + "log\\" + "logErrors.txt";
                try
                {
                    XMLReader readXML = new XMLReader();
                    var data = readXML.ReturnListOfProducts().ToList();

                }
                catch (Exception e)
                {
                    var sw = new System.IO.StreamWriter(filename, true);
                    sw.WriteLine(DateTime.Now.ToString() + " " + e.Message + " " + e.InnerException);
                    sw.Close();
                }
               // return View(data.ToList());
                XMLReader readXML2 = new XMLReader();
                var data2 = readXML2.ReturnListOfProducts();

                var sw2 = new System.IO.StreamWriter(filename, true);
                sw2.WriteLine(DateTime.Now.ToString() + " " + data2);
                sw2.Close();

                return PartialView("_VoIPSubform1", data2);

           //     return View("_VoIPSubform1", data.ToList());
            }  

如果有人對解決方案感興趣,我將這些行添加到控制器內,並且可以正常工作。

ViewData["data"] = data2;
return PartialView("_VoIPSubform1");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM