This question is locked. New answers and comments are not allowed.
I need to bind my MVC Chart control to a DataTable. Does the control support this?
I started a new MVC3 project, and this is the contents of my Index.cshtml file:
This is my _Layout.cshtml file:
And finally, my HomeController.cs:
When I run this, I get the following error:
Exception Details: System.InvalidOperationException: A circular reference was detected while serializing an object of type 'System.Reflection.RuntimeModule'.
Source Error:
Source File: c:\temp\MvcApplication2\MvcApplication2\Views\Shared\_Layout.cshtml Line: 35
Stack Trace:
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
Am I doing something wrong? Again, all I need to do is bind my MVC Chart control to a DataTable. Does the control support this?
I started a new MVC3 project, and this is the contents of my Index.cshtml file:
@using Telerik.Web.Mvc.UI@using System.Data@using System.Linq@{ ViewBag.Title = "Home Page"; DataTable table = ViewBag.Table as DataTable;}<h2>@ViewBag.Message</h2><p>@(Html.Telerik().Chart(table.Rows.OfType<DataRow>()).Name("Chart1"))</p>This is my _Layout.cshtml file:
@using Telerik.Web.Mvc.UI<!DOCTYPE html><html><head> <meta charset="utf-8" /> <title>@ViewBag.Title</title> <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" /> @(Html.Telerik().StyleSheetRegistrar().DefaultGroup(g => g.Add("telerik.common.css").Add("telerik.default.min.css"))) <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script></head><body> <div class="page"> <header> <div id="title"> <h1>My MVC Application</h1> </div> <div id="logindisplay"> @Html.Partial("_LogOnPartial") </div> <nav> <ul id="menu"> <li>@Html.ActionLink("Home", "Index", "Home")</li> <li>@Html.ActionLink("About", "About", "Home")</li> </ul> </nav> </header> <section id="main"> @RenderBody() </section> <footer> </footer> </div> @Html.Telerik().ScriptRegistrar()</body></html>And finally, my HomeController.cs:
public class HomeController : Controller { public ActionResult Index() { ViewBag.Message = "Welcome to ASP.NET MVC!"; DataTable table = new DataTable("Blah"); table.Columns.AddRange(new DataColumn[] { new DataColumn("Col1", typeof(string)), new DataColumn("Col2", typeof(int)) }); table.Rows.Add("Test", 5); table.Rows.Add("Test2", 53); table.Rows.Add("Test3", 215); table.Rows.Add("Test4", 15); table.Rows.Add("Test5", 2); ViewBag.Table = table; return View(); } public ActionResult About() { return View(); } }When I run this, I get the following error:
A circular reference was detected while serializing an object of type 'System.Reflection.RuntimeModule'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.InvalidOperationException: A circular reference was detected while serializing an object of type 'System.Reflection.RuntimeModule'.
Source Error:
|
Source File: c:\temp\MvcApplication2\MvcApplication2\Views\Shared\_Layout.cshtml Line: 35
Stack Trace:
|
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
Am I doing something wrong? Again, all I need to do is bind my MVC Chart control to a DataTable. Does the control support this?