[CLOSED] [#505] Mixing MVC and non-MVC Ext v2x

Page 1 of 3 123 LastLast
  1. #1

    [CLOSED] [#505] Mixing MVC and non-MVC Ext v2x

    Is it possible, and what is correct way to use Ext.net MVC version in mixed environment (web forms and MVC)?

    Can we install both versions from Nuget library and us them in the mixed environment?

    We are encountering problems (rendering issues) when moving from an Ext MVC page back to an Ext webform page because of the following code:
          public static void MarkAsMVC()
           {
               if (HttpContext.Current.Application["Ext.Net.MVC.IsMVC"] == null)
               {
                   HttpContext.Current.Application["Ext.Net.MVC.IsMVC"] = new object();
               }
           }
     
           public static bool IsMVC
           {
               get
               {
                   return HttpContext.Current.Application["Ext.Net.MVC.IsMVC"] != null;
               }
           }
    Can this method and property below be changed to use Items collection instead of Application state, or is there a simple solution?

    We are currently using v2.4 and will not be able to upgrade until after our next release in late July.
    Last edited by Daniil; Nov 07, 2014 at 9:48 AM. Reason: [CLOSED]
  2. #2
    Hi

    What kind of problem do you have? Should not be any problems to use webform page inside MVC application
  3. #3
    Simple explanation of problem is that direct methods are not registered on client.
    When we attempt to call a direct method, in this case, to reload the page in "Edit" mode, the error in javascript is "Ext.net.DirectMethods is undefined".

    .. and I think it is because of this:

    public virtual string BuildDirectMethodProxies(bool dynamicOnly)
            {
                if (this.DirectMethodProxy == ClientProxy.Ignore)
                {
                    return "";
                }
    #if MVC
                if (this.IsMVC)
                {
                    if (dynamicOnly || this.ViewContext == null)
                    {
                        return "";
                    }
                    
                    return Ext.Net.MVC.MvcDirectMethod.BuildProxy(this.ViewContext);
                }
    #endif
    I would expect that ViewContext is obviously null for Web Forms page.
    Even if it is not, code would go to Ext.Net.MVC.MvcDirectMethod.BuildProxy
  4. #4
    Direct methods cannot be registered inside WebForm page in the MVC application because WebForm page is requested through controller any way (you return ViewResult to render that page). Therefore direct method handler is not available after webform page rendering
  5. #5
    I am not sure I follow your logic. We use directmethods on 85% of the pages in our application. We have been using Ext since v.8. The problem only occurs when we go from an MVC page to an Ext v2.4 page. Once we do that, the flag , isMVC, is set, and we no longer have access to DirectMethods functionality.
  6. #6
    Do not confuse MVC application and WebForm application
    You can use WebForm page inside MVC aplication but the page instance is created only once (when you render it inside controller action using ViewResult) instead every request page recreation in WebForm application

    So, the page instance is never recreated after webform page rendering in the MVC application and we cannot get direct event/method handler after that. All direct event/method handlers must be controller actions only in MVC application (even if request was initiated from webform page)

    I am not sure I follow your logic. We use directmethods on 85% of the pages in our application. We have been using Ext since v.8. The problem only occurs when we go from an MVC page to an Ext v2.4 page. Once we do that, the flag , isMVC, is set, and we no longer have access to DirectMethods functionality.
    You use it in WebForm application (not MVC application). WebForm and MVC applications have different life cycle. Do not rely WebForm concepts inside MVC application. You cannot reach direct handler in web form page (view) even if you remove that flag because page (view) instance is not recreated like in WebForm application
  7. #7
    This might clarify situation that we have (or make it more confusing).

    Timeline:
    - WebForms application was using Ext.Net library.

    - WebForms application was modified to support MVC architecture. (we got hybrid that is serving both MVC views and WebForms aspx pages)

    - In order to use Ext.Net controls in razor views Ext.Net was replaced with Ext.Net.MVC.

    - Also expectation was that Controls from Ext.Net.MVC version should work in WebForms environment and that seems to be truth.

    - WebForms (aspx) pages with Ext.Net controls continued to work correctly (although we now are using Ext.net.MVC)

    - When debugging from WebForms pages ResourceManager.IsMVC is never true.

    - Ext.net ResourceManager is added to views and from the moment that view is hit WebForms pages are not working as expected.

    Reason - ResourceManager.IsMVC returns true for every request (even for those that are handled by WebForms)

    Reason - HttpContext.Current.Application["Ext.Net.MVC.IsMVC"] is set when resource manager helper is used on view.

    Could this be possible solution - Use HttpContext.Current.Items["Ext.Net.MVC.IsMVC"]

    This would make ResourceManager.IsMVC property "request specific" and prevent using MVC specific code in BaseControl when controls are rendered for WebForms request.

    I hope that this make some sense


    Thanks
    Milan
  8. #8
    Well, you have to understand that WebForm page life cycle is different in the MVC application if compare with WebForm application
    Any handlers inside WebForm page cannot be executed after that page rendering because MVC application doesn't recreate page instance like WebForm application when you request a page

    Reason - ResourceManager.IsMVC returns true for every request (even for those that are handled by WebForms)
    yes, ResourceManager.IsMVC is application level property (not per page/view)

    Reason - HttpContext.Current.Application["Ext.Net.MVC.IsMVC"] is set when resource manager helper is used on view.
    No, the reason is described in top of this post (page is not recreated automatically for requests)

    Could this be possible solution - Use HttpContext.Current.Items["Ext.Net.MVC.IsMVC"]

    This would make ResourceManager.IsMVC property "request specific" and prevent using MVC specific code in BaseControl when controls are rendered for WebForms request.
    No, replacing Application to Items will not solve your issue. Just take note of direct event/method handlers must be defined in controller class (even if request was initiated from WebForm page) because it is MVC application, all requests are handled by controller only (or before controller), request cannot be handled by view (webform page)
  9. #9
    As I said we have hybrid setup
    WebForms aspx pages are not processed by mvc engine (we are not using them instead of razor views if that is what you think), they have code behind and they are going through full life cycle.
    Pages are working good, DirectMethods are registered on client, everything is working fine as if we are not using Ext.Net.MVC at all.
    Problem appears when resource builder is used on one of the views that is actually processed by MVC engine.
    After that we still have full page life cycle on those pages but resource manager is considering itself as MVC and starts producing results for MVC app. (meaning no more DirectMethods scripts - which I understand are not good for MVC anyway)
    But thing is we are using also pages with code behind that are can work with direct methods.

    Reason why our pages are working ok is that MarkAsMVC() is called only when you use MvcResourceManagerBuilder (called from ResourceManager helper).
    And as long IsMVC is false we are ok
    public virtual string BuildDirectMethodProxies(bool dynamicOnly)
            {
                if (this.DirectMethodProxy == ClientProxy.Ignore)
                {
                    return "";
                }
    #if MVC
                if (this.IsMVC)
                {
                    if (dynamicOnly || this.ViewContext == null)
                    {
                        return "";
                    }
                    
                    return Ext.Net.MVC.MvcDirectMethod.BuildProxy(this.ViewContext);
               }
    #endif
                Dictionary<string, Dictionary<string, DirectMethodList>> methods = this.GroupDirectMethodsByNamespace(dynamicOnly);
                StringBuilder sb = new StringBuilder(256);
                
                foreach (KeyValuePair<string, Dictionary<string, DirectMethodList>> ns in methods)
                }
    So your code will produce DirectMethods

    When resource builder is created it is calling MarkAsMVC() and setting that application property and IsMVC becomes true.

    Anyway I had inherited MvcResourceManagerBuilder just to do this
    public class VMSResourceManagerBuilder : MvcResourceManagerBuilder
        {
            #region Constructors and Destructors
    
            /// <summary>
            /// Initializes a new instance of the <see cref="VMSResourceManagerBuilder"/> class.
            /// </summary>
            public VMSResourceManagerBuilder()
            {
                HttpContext.Current.Application["Ext.Net.MVC.IsMVC"] = null;
            }
    
            #endregion
        }

     public static VMSResourceManagerBuilder VMSResourceManager(this BuilderFactory factory)
            {
                return new VMSResourceManagerBuilder();
            }
    And this is helping us.

    I understand that we are probably misusing Ext.Net.MVC inside Webforms pages but it seems that everything else is ok because in your code it is always checking for that IsMVC flag, so if it is false code will produce result as it would Ext.net.

    Fell free to quit this thread if you think that this is not leading anywhere.

    Thanks for your time and help so far

    Milan
  10. #10
    I am not familiar with such hybrid system which you use.
    Can you provide more details (for example, articles in internet)?

    Jsut intresting, at which place, web form page is recreated automatically in MVC application
Page 1 of 3 123 LastLast

Similar Threads

  1. [CLOSED] RowExpander mixing up data in IE8
    By HansWapenaar in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Apr 20, 2013, 12:34 PM
  2. [CLOSED] Mixing Container Items and Content
    By sisa in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Aug 23, 2012, 1:05 PM
  3. Replies: 1
    Last Post: Mar 17, 2009, 1:17 AM
  4. EnablePageMethods & Mixing managers..
    By alexandern in forum Open Discussions
    Replies: 2
    Last Post: Jun 06, 2008, 4:53 PM

Posting Permissions