ASP.NET MVC - 如何使用arraylist数据显示部分视图 [英] ASP.NET MVC - How to show partial views with arraylist data

查看:62
本文介绍了ASP.NET MVC - 如何使用arraylist数据显示部分视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我想根据所选按钮在aspx网页上显示三个不同的局部视图。那部分工作正常。

但是每个部分视图都会从xml文件中读取单独的部分,并且还会为视图提供数据。



我试图将数据作为Arraylist传递给视图,但部分视图现在不显示。没有传递数据,部分视图正在工作。



请注意我使用的是aspx而不是剃须刀。



关于如何使这项工作的任何想法,以便在点击3个按钮中的任何一个时,也会显示不同的局部视图以及xml数据。



提前致谢。



RenderVOIP.aspx



Hi,

I want to display three different partial views on a aspx webpage based on the buttons selected. That part is working fine.
But then each of the partial views would read separate sections from the xml file and would provide data the view as well.

I have tried to pass the data as Arraylist to the view but the partial view does not show up now. Without passing the data, the partial views were working.

Please note I am using aspx instead of razor.

Any ideas as to how to make this work so that upon clicking any of the 3 buttons, a different partial view is displayed with the xml data as well.

Thanks in advance.

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";
          
               // return View(data.ToList());
                XMLReader readXML2 = new XMLReader();
                var data2 = readXML2.ReturnListOfProducts();

       

                return PartialView("_VoIPSubform1", data2);

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

推荐答案

(function(){
(function() {


('#InfoButton' ).on(click,function(){
('#InfoButton').on("click", function() {


.get('<% = Url.Action(< span class =code-string> InfoAction HardwareRequisition%> ',function(data){
.get('<%= Url.Action("InfoAction", "HardwareRequisition")%>', function (data) {


这篇关于ASP.NET MVC - 如何使用arraylist数据显示部分视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆