This is a migrated thread and some comments may be shown as answers.

[Solved] ViewUserControl error when clicking on grid header

2 Answers 99 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Christopher Ronak
Top achievements
Rank 1
Christopher Ronak asked on 25 Mar 2010, 04:20 AM
Hello,

I'm getting the following error when I click on a header of my grid (to sort by that column):
Exception Details: </b>System.InvalidOperationException: A ViewUserControl can only be used inside 
pages that derive from ViewPage

Debugging through, it is going to the controller fine and returning the data as expected, however this error is occurring somewhere along the way.  I am rendering the grid inside a .ascx file which is being loaded by an Ajax load (jquery.load()) into a #div location. The parent file is also a .ascx file. This error is confusing me because the grid appears fine when it first loads. It's only on the postback to update data that it encounters the error. I don't get why the grid even cares whether it's a viewpage or viewuser control. It should only be interested in the data, right?
Here's what I'm using:
MVC v1
c#
IE 8 and Firefox 3.5.8 browsers (error occurs on both)
jquery 1.4.2
Teleric mvc Q1 2010
MS XP Pro and Vista Ultimate (error occurs on both)

Here is the view (i've commented out some stuff since grouping and filtering cause different errors which i'll get to later). The file is called ProjectDataAnalyzer.ascx:

<%@ Control Language="C#"  Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<JetSoft.Jet.Controllers.Project.ProjectTransactionsViewModel>>" %> 
<%@ Import Namespace="JetSoft.Jet.Controllers.Project"%> 
 
 
<% Html.Telerik().Grid<ProjectTransactionsViewModel>(Model)  
        .Name("Grid")  
        .Columns(columns => 
        {  
            columns.Bound(o => o.ResourceName).Title("Resource Name").Width(120);  
            columns.Bound(o => o.ResourceClass).Title("Class").Width(120);  
            columns.Bound(o => o.Quantity).Width(80);  
            columns.Bound(o => o.RateUnit).Width(50);  
            columns.Bound(o => o.Task).Title("Task").Width(120);  
            columns.Bound(o => o.EffectiveDate).Format("{0:MM/dd/yyyy}").Width(80).Title("Work Date");  
            columns.Bound(o => o.CostValue).Title("Cost");  
            columns.Bound(o => o.BillableValue).Title("Billable");  
            columns.Bound(o => o.Margin).Title("Margin").Format("%");  
        })  
//          .Ajax(ajax => ajax.Action("ProjectTransactions", "Project"))  
//        .Groupable()  
        .DataBinding(dataBinding => dataBinding.Ajax().Select("UpdateGrid", "Project"))  
        .Scrollable()  
        .Sortable()  
//        .Filterable()  
        .Render();  
%> 
 

And here are the relevant methods from the controller. The first method is called by the initial ajax load.
        public ActionResult ProjectDataAnalyzer()  
        {  
           
            return PartialView("ProjectDataAnalyzer", ProjectTransactions());  
        }  
 
 
        private IEnumerable<ProjectTransactionsViewModel> ProjectTransactions()  
        {  
            int projectId = Int32.Parse(Request.Params.Get("ProjectId"));  
            var today = DateTime.Today;  
            var aYearAgo = new DateTime(today.Year - 1, today.Month - 1, today.Day);  
            IEnumerable<ProjectTransactionsViewModel> transactions = ProjectEntity.ProjectTransactions(projectId, aYearAgo, today);  
            return transactions;  
        }  
 
        [GridAction]  
        public ActionResult UpdateGrid()  
        {  
           
            IEnumerable<ProjectTransactionsViewModel> transactions = ProjectTransactions();  
            return this.PartialView(new GridModel(transactions));  
        }  
 

Thank you for any help,

Chris

2 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 25 Mar 2010, 09:15 AM
Hi Christopher Ronak,

Unfortunately we have never encountered this problem before. This exception should not be thrown by the grid at all. Does this all work fine if you remove the grid? Can you send us a sample running project?

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Christopher Ronak
Top achievements
Rank 1
answered on 25 Mar 2010, 06:12 PM
Hi Atanas,

Thanks for your response.

Yes, everything works fine without the grid. And everything works fine with the grid until a postback is requested. This error is contained only to when clicking on the column header of the grid (to sort it) - and I assume any other postback like, filter, groupby etc. I had been using jqgrid in this same way and I'm trying to replace it with the teleric grid - so this error is specific to how i'm using the teleric grid. Is there potentially an issue with the fact that I'm using mvc v1?
I've today changed all ascx files to be aspx files in the calling chain to see if that makes a difference. Still the same error. 
I'll work on getting you a working example - but this'll take some effort. In the meantime, I've attached the full error from firebug.

Thanks for any help,

Chris
<html> 
    <head> 
        <title>A ViewUserControl can only be used inside pages that derive from ViewPage or ViewPage&lt;TViewItem&gt;.</title> 
        <style> 
         body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}   
         p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}  
         b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}  
         H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }  
         H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }  
         pre {font-family:"Lucida Console";font-size: .9em}  
         .marker {font-weight: bold; color: black;text-decoration: none;}  
         .version {color: gray;}  
         .error {margin-bottom: 10px;}  
         .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }  
        </style> 
    </head> 
 
    <body bgcolor="white">  
 
            <span><H1>Server Error in '/' Application.<hr width=100size=1 color=silver></H1> 
 
            <h2> <i>A ViewUserControl can only be used inside pages that derive from ViewPage or ViewPage&lt;TViewItem&gt;.</i> </h2></span>  
 
            <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">  
 
            <b> Description: </b>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.  
 
            <br><br>  
 
            <b> Exception Details: </b>System.InvalidOperationException: A ViewUserControl can only be used inside pages that derive from ViewPage or ViewPage&lt;TViewItem&gt;.<br><br>  
 
            <b>Source Error:</b> <br><br>  
 
            <table width=100bgcolor="#ffffcc">  
               <tr> 
                  <td> 
                      <code> 
 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.</code> 
 
                  </td> 
               </tr> 
            </table> 
 
            <br> 
 
            <b>Stack Trace:</b> <br><br>  
 
            <table width=100bgcolor="#ffffcc">  
               <tr> 
                  <td> 
                      <code><pre>  
 
[InvalidOperationException: A ViewUserControl can only be used inside pages that derive from ViewPage or ViewPage&lt;TViewItem&gt;.]  
   System.Web.Mvc.ViewUserControl.get_ViewPage() +104473  
   System.Web.Mvc.ViewUserControl.get_ViewContext() +13  
   System.Web.Mvc.ViewUserControl.get_Ajax() +32  
 
[TargetInvocationException: Exception has been thrown by the target of an invocation.]  
   System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct&amp; sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +0  
   System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +71  
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +350  
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29  
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +546  
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +1338  
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +175  
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeEnumerable(IEnumerable enumerable, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +129  
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +1294  
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +175  
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +566  
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +1338  
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +175  
   System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat) +24  
   System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, SerializationFormat serializationFormat) +74  
   System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj) +6  
   System.Web.Mvc.JsonResult.ExecuteResult(ControllerContext context) +254  
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +10  
   System.Web.Mvc.&lt;&gt;c__DisplayClass11.&lt;InvokeActionResultWithFilters&gt;b__e() +20  
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +251  
   System.Web.Mvc.&lt;&gt;c__DisplayClass13.&lt;InvokeActionResultWithFilters&gt;b__10() +19  
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +178  
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +399  
   System.Web.Mvc.Controller.ExecuteCore() +126  
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +27  
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7  
   System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +151  
   System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +57  
   System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +7  
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181  
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +75  
</pre></code>  
 
                  </td> 
               </tr> 
            </table> 
 
            <br> 
 
            <hr width=100size=1 color=silver>  
 
            <b>Version Information:</b>&nbsp;Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.3082  
 
            </font> 
 
    </body> 
</html> 
<!--   
[InvalidOperationException]: A ViewUserControl can only be used inside pages that derive from ViewPage or ViewPage&lt;TViewItem&gt;.  
   at System.Web.Mvc.ViewUserControl.get_ViewPage()  
   at System.Web.Mvc.ViewUserControl.get_ViewContext()  
   at System.Web.Mvc.ViewUserControl.get_Ajax()  
[TargetInvocationException]: Exception has been thrown by the target of an invocation.  
   at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)  
   at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)  
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)  
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)  
   at System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)  
   at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)  
   at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)  
   at System.Web.Script.Serialization.JavaScriptSerializer.SerializeEnumerable(IEnumerable enumerable, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)  
   at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)  
   at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)  
   at System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)  
   at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)  
   at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)  
   at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat)  
   at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, SerializationFormat serializationFormat)  
   at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj)  
   at System.Web.Mvc.JsonResult.ExecuteResult(ControllerContext context)  
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)  
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass11.<InvokeActionResultWithFilters>b__e()  
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)  
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass11.<>c__DisplayClass13.<InvokeActionResultWithFilters>b__10()  
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)  
   at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)  
   at System.Web.Mvc.Controller.ExecuteCore()  
   at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)  
   at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext)  
   at System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext)  
   at System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext)  
   at System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext)  
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()  
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)  
 
Tags
Grid
Asked by
Christopher Ronak
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Christopher Ronak
Top achievements
Rank 1
Share this question
or