这是我的代码。我在Mvc4中的视图列表。如何在视图中检索已发送的数据 [英] This Is My Code. I Am Pasing List To The View In Mvc4. How Do I Retrieve The Sent Data In View

查看:61
本文介绍了这是我的代码。我在Mvc4中的视图列表。如何在视图中检索已发送的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

// Controller_code

//Controller_code

public ActionResult Index()
        {
            slider slider = new slider();
            XmlDocument xmldoc = new XmlDocument();
            // XmlNodeList xmlnode; int i = 0; string str = null;
            xmldoc.Load("D:/Data/Projects/AML/AML/AML/imagePath.xml");
            int nodecount = xmldoc.SelectNodes("/images/imagepath").Count;
            string[] imagepaths= new string[nodecount];
            string[] imageText = new string[nodecount];
            List<slider> imageList = new List<slider>();
            for(int i=0;i<nodecount;i++)>
            {
                imageList.Add(new slider
                {
                  imagepaths=Convert.ToString(xmldoc.GetElementsByTagName("path")[i].InnerText),
                   imageText=Convert.ToString(xmldoc.GetElementsByTagName("text")[i].InnerText)
                });
            }
            return View(imageList.Select(
                   m => new
                   {
                       path = m.imagepaths,
                       text = m.imageText
                   }));
           }

推荐答案

您好b $ b

请尝试如下:



Hi
Please try like below:

public ActionResult Index()
        {
            slider slider = new slider();
            XmlDocument xmldoc = new XmlDocument();
            // XmlNodeList xmlnode; int i = 0; string str = null;
            xmldoc.Load("D:/Data/Projects/AML/AML/AML/imagePath.xml");
            int nodecount = xmldoc.SelectNodes("/images/imagepath").Count;
            string[] imagepaths= new string[nodecount];
            string[] imageText = new string[nodecount];
            List<slider> imageList = new List<slider>();
            for(int i=0;i<nodecount;i++)>
            {
                imageList.Add(new slider
                {
                  imagepaths=Convert.ToString(xmldoc.GetElementsByTagName("path")[i].InnerText),
                   imageText=Convert.ToString(xmldoc.GetElementsByTagName("text")[i].InnerText)
                });
            }
            return View();
           }





查看





View

@model IEnumerable<slider>


 <div>
                    @{
                        foreach (var a in @Model)
                        { 
                        
                               <table>
                                   <tr>
                                       <td>@a.imageList</td>
                                   </tr>
                                   <tr><td>@a.imageText</td></tr>
                               </table>
                    
                        }
                    }


                </div>


</mvcapptest.controllers.homecontroller.slider>







问候

Dominic




Regards
Dominic


这篇关于这是我的代码。我在Mvc4中的视图列表。如何在视图中检索已发送的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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