Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
//Controller_code
C#
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
                   }));
           }
Posted
Updated 29-Jan-15 3:03am
v2
Comments
Tejas Vaishnav 29-Jan-15 9:05am    
Can you please give more detail, not able to understand what you want?

1 solution

Hi
Please try like below:

C#
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

HTML
@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>



Regards
Dominic
 
Share this answer
 
v4
Comments
dirtyshooter 30-Jan-15 2:06am    
Thanks Dominic. That helped a lot.
Dominic Abraham 30-Jan-15 7:25am    
Its nice to hear that solution helped you :-) Don't forget to mark it as answer whenever some answers
help you !!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900