[CLOSED] [#549] Rendering Partial View Error

  1. #1

    [CLOSED] [#549] Rendering Partial View Error

    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.<BeginInv okeAction>b__1c() +321
    System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInv okeAction>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(IAsy ncResult 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
    Last edited by Daniil; Oct 01, 2014 at 12:37 PM. Reason: [CLOSED]
  2. #2
    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
  3. #3
    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)
  4. #4
    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
  5. #5
    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.
  6. #6
    Thank you. I will wait to hear something. I appreciate the help to find a solution.
    LAE
  7. #7
    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.
  8. #8
    Sorry

    I just got notification. I will get latest and update back. Thank you
  9. #9
    I have tried the new revision and it is working just fine. Thank you very much for fixing this.
    lae

    EDIT: please consider closed.
  10. #10
    Thank you for the feedback!

Similar Threads

  1. Replies: 1
    Last Post: May 12, 2014, 11:50 AM
  2. [CLOSED] Partial View not Rendering
    By RCM in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 01, 2013, 3:10 AM
  3. [CLOSED] Problem rendering partial view
    By T3rryChan in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Jul 03, 2012, 9:22 PM
  4. [CLOSED] rendering desktop windows using partial view
    By SymSure in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Jan 11, 2012, 6:42 PM
  5. [CLOSED] Dynamically Added Tab not rendering partial view
    By SymSure in forum 1.x Legacy Premium Help
    Replies: 13
    Last Post: Apr 26, 2011, 9:10 PM

Posting Permissions