I am relatively new when it comes to asp.net MVC 5 and I am trying to display the contents of an xml file ( which is located in the content folder of my project for ease of access) and display the contents on a simple view. the code from my controller, modelclass and view are below.....
The Error I am getting is as follows
The model item passed into the dictionary is of type 'System.Collections.Generic.List
1[System.Xml.Linq.XElement]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable
1[XML_v1._0.Models.XML_details]'.
The code for my controller, modelclass and view are below.....
The View
@model IEnumerable<XML_v1._0.Models.XML_details>
}
<head>
<title></title>
<style>
th {
font-size: 300%;
}
td {
font-size: 300%;
}
</style>
</head>
<h2>Line Status</h2>
<div>
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.Line)
</th>
<th>
@Html.DisplayNameFor(model => model.Status)
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Line)
</td>
<td>
@Html.DisplayFor(modelItem => item.Status)
</td>
</tr>
}
</table>
</div>
The Controller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using XML_v1._0.Models;
using System.Xml.Linq;
using System.Xml;
using System.Text;
using System.Collections;
using System.Dynamic;
namespace XML_v1._0.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
XDocument L_tube = XDocument.Load(@"C:\Users\070339\Documents\Visual Studio 2013\Projects\Learning and practice\XML v1.0\XML v1.0\Content\tube.xml");
var train = from s in L_tube.Descendants() select s;
var model = train.ToList();
return View(model);
}
}
}
The Model
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using XML_v1._0.Models;
using System.Xml.Linq;
using System.Xml;
using System.Text;
using System.Collections;
using System.Dynamic;
namespace XML_v1._0.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
XDocument L_tube = XDocument.Load(@"C:\Users\070339\Documents\Visual Studio 2013\Projects\Learning and practice\XML v1.0\XML v1.0\Content\tube.xml");
var train = from s in L_tube.Descendants() select s;
var model = train.ToList();
return View(model);
}
}
}
Any help would be appreciated.
No comments:
Post a Comment