我正在尝试获取Windows事件日志并在html页面中显示。我正在使用asp.net MVC 5,但面临这个问题。请帮助我,我将非常感谢你。
请参阅错误链接
传递到字典中的模型项的类型为' System.Collections.Generic.List' 1 [System.Object]',但此字典需要类型为&#39的模型项; System.Collections.Generic.IEnumerable' 1 [WebApplication1.Models.Eventlogg]'
这是我的代码
public ActionResult Index()
{
string eventLogName = "Application";
string sourceName = "EventLoggingApp";
string machineName = "nb-ahja1";
EventLog eventLog;
eventLog = new EventLog();
eventLog.Log = eventLogName;
eventLog.Source = sourceName;
eventLog.MachineName = machineName;
var model = new List<object>();
foreach (EventLogEntry log in eventLog.Entries)
{
model.Add(log.Source);
}
return View(model);
}
public class Eventlogg
{
public string Source { get; set; }
}
@model IEnumerable<WebApplication1.Models.Eventlogg>
@{
ViewBag.Title = "Home Page";
}
@foreach (var item in Model)
{
<div>
@item.Source
<hr />
</div>
}