PDA

View Full Version : [CLOSED] [#549] Rendering Partial View Error



LAEUser
Sep 14, 2014, 2:49 PM
Hi

I am calling a partial view from an external project using MvcRazorgenerator tool. I am getting the following error when i load the partial through my action in the controller.




Unable to cast object of type 'RazorGenerator.Mvc.PrecompiledMvcView' to type 'System.Web.Mvc.WebFormView'.
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.InvalidCastException: Unable to cast object of type 'RazorGenerator.Mvc.PrecompiledMvcView' to type 'System.Web.Mvc.WebFormView'.

Source Error:
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.

Stack Trace:
[InvalidCastException: Unable to cast object of type 'RazorGenerator.Mvc.PrecompiledMvcView' to type 'System.Web.Mvc.WebFormView'.]
Ext.Net.MVC.PartialViewResult.ExecuteResult(Contro llerContext context) +2553
System.Web.Mvc.ControllerActionInvoker.InvokeActio nResult(ControllerContext controllerContext, ActionResult actionResult) +39
System.Web.Mvc.ControllerActionInvoker.InvokeActio nResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +116
System.Web.Mvc.ControllerActionInvoker.InvokeActio nResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +529
System.Web.Mvc.ControllerActionInvoker.InvokeActio nResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +529
System.Web.Mvc.ControllerActionInvoker.InvokeActio nResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +106
System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +321
System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +185
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndD elegate(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End( ) +133
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsync Result asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncControllerActionInvoker. EndInvokeAction(IAsyncResult asyncResult) +40
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +34
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDel egate(IAsyncResult asyncResult) +70
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End( ) +139
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsync Result asyncResult, Object tag) +59
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsync Result asyncResult, Object tag) +40
System.Web.Mvc.Controller.EndExecuteCore(IAsyncRes ult asyncResult) +44
System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +39
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDel egate(IAsyncResult asyncResult) +62
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End( ) +139
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsync Result asyncResult, Object tag) +59
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsync Result asyncResult, Object tag) +40
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAs yncController.EndExecute(IAsyncResult asyncResult) +39
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +39
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDel egate(IAsyncResult asyncResult) +70
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End( ) +139
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsync Result asyncResult, Object tag) +59
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsync Result asyncResult, Object tag) +40
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsync Result asyncResult) +40
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHan dler.EndProcessRequest(IAsyncResult result) +38
System.Web.CallHandlerExecutionStep.System.Web.Htt pApplication.IExecutionStep.Execute() +9651188
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean& completedSynchronously) +155


Controller Code - this is called from a JS file that add a tab to main Tab control called pnlCenter


public Ext.Net.MVC.PartialViewResult Test()
{
RazorGenerator.Mvc.PrecompiledMvcEngine eng = this.ViewEngineCollection[0] as RazorGenerator.Mvc.PrecompiledMvcEngine;
RazorGenerator.Mvc.PrecompiledMvcView v = eng.FindPartialView(this.ControllerContext, "Test", false).View as RazorGenerator.Mvc.PrecompiledMvcView;

// view is loaded via ajax request (DirectEvent) therefore script tags will be deactivated automatically
var result = new Ext.Net.MVC.PartialViewResult
{
View = v,
//ViewName = "Test",
ContainerId = "plnCenter",
RenderMode = RenderMode.AddTo
};
return result;
}


View called Test - Please note that if I remove the panel and just have html code. the view loads fine from the external project. Also loading a partial view from my main application loads fine.


@using SDRMA.Core.Web
@using System.Web.Optimization;
@using Ext.Net;
@using Ext.Net.MVC;

@{
ViewBag.Title = "Test Module";
//Layout = "~/Views/Shared/_Layout.cshtml";
Layout = null;
}

@(
Html.X().Panel()
.Title(DateTime.Now.ToLongTimeString())
.Closable(true)
.Layout(LayoutType.Fit)
.Html(
@<text>
<h1>HOME MODULE AREA</h1>
<h2>Hello! This is a Razor View that is loaded from an external project/assembly.<br /><br />(PluginHome - test page)</h2>
</text>
)
)


please note that it is trying to cast to System.Web.Mvc.WebFormView' when it should be using razorengine. WebformEngine is turned off.
Any suggestions. Do I need to create my own partialViewExecute method. Thanks

LAEUser
Sep 14, 2014, 5:02 PM
I Am still testing this but I think I have found the problem. in PartialViewResult.cs, in the ExecuteResult method, there is an if statement



if (this.View is RazorView)
{
.......
}


I believe this should be



if (this.View is IView)
{
.....
}


Can you explain the reasoning why the code is looking specifically for RazorView when developers can have they own engines and views deriving from IView. is this an oversight. Because it ignores the if statement, it falls down to the rest of the code which is assuming you are using webforms.

thank you

Vladimir
Sep 14, 2014, 8:20 PM
Hi,

Ext.Net supports two engines only for dynamic rendering: WebForm and Razor because we must know engine spefication (for example, Razor view should be dynamically rendered differently than WebForm view because Razor has no controls and no controls hierarchy)

LAEUser
Sep 15, 2014, 10:54 AM
I can understand for webforms. but in the case of MVC, that does not make sense as there is a need to use a custom view engine. By changing to IView, my partial page is now rendering properly. I rather not have to maintain this moving forward. Can you please discuss this internally and see what can be done. This will be limiting and I really don't want to change to another framework as I like using Ext.Net.
thanks

Daniil
Sep 15, 2014, 6:10 PM
Created an Issue:
https://github.com/extnet/Ext.NET/issues/549

We are going to make some change that should improve the situation. Once the change is committed to SVN, we will let you know and you will be able to test.

LAEUser
Sep 15, 2014, 6:51 PM
Thank you. I will wait to hear something. I appreciate the help to find a solution.
LAE

Daniil
Sep 19, 2014, 12:57 PM
We've made some change in the revision #5978 (SVN trunk). It should help with your scenario. Please update and retest. We would appreciate if you confirm it works for you or not.

LAEUser
Sep 29, 2014, 12:53 PM
Sorry

I just got notification. I will get latest and update back. Thank you

LAEUser
Sep 30, 2014, 5:38 PM
I have tried the new revision and it is working just fine. Thank you very much for fixing this.
lae

EDIT: please consider closed.

Daniil
Oct 01, 2014, 1:36 PM
Thank you for the feedback!