Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.NET MVC-如何使用arraylist数据显示局部视图_C#_Jquery_Asp.net Mvc_Asp.net Ajax - Fatal编程技术网

C# ASP.NET MVC-如何使用arraylist数据显示局部视图

C# ASP.NET MVC-如何使用arraylist数据显示局部视图,c#,jquery,asp.net-mvc,asp.net-ajax,C#,Jquery,Asp.net Mvc,Asp.net Ajax,我想根据所选按钮在aspx网页上显示三种不同的局部视图。那部分很好用。但是,每个局部视图都将从xml文件中读取单独的部分,并为视图提供数据。我曾尝试将数据作为Arraylist传递给视图,但现在不显示部分视图。在未传递数据的情况下,局部视图正在工作。请注意,我使用的是aspx而不是razor。关于如何实现此功能的任何想法,以便在单击3个按钮中的任何一个按钮时,也会显示包含xml数据的不同局部视图。提前谢谢 RenderVOIP.aspx $(function() { $('#In

我想根据所选按钮在aspx网页上显示三种不同的局部视图。那部分很好用。但是,每个局部视图都将从xml文件中读取单独的部分,并为视图提供数据。我曾尝试将数据作为Arraylist传递给视图,但现在不显示部分视图。在未传递数据的情况下,局部视图正在工作。请注意,我使用的是aspx而不是razor。关于如何实现此功能的任何想法,以便在单击3个按钮中的任何一个按钮时,也会显示包含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");