[CLOSED] EXT.NET 7.0 Core - Direct Method Handler/Call Issue

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    [CLOSED] EXT.NET 7.0 Core - Direct Method Handler/Call Issue

    Dear,

    Please note that I encountered an issue when clicking a <ext-button> (MVC) having a direct method as a listeners.
    Noting that I tried the same instructions listed in the following page URL:
    https://examples.ext.net/#/window/basic/hello_world

    Problem description:
    when clicking on the button, it alerts the following:
    Request Failure (Attached).
      Console Error:  
      ShowWindowDirect:1 Failed to load resource: the server responded with a status of 404 ()
    Click image for larger version. 

Name:	Error1.jpg 
Views:	99 
Size:	51.6 KB 
ID:	25458

     //TestDirect.cshtml
    
    @page
    @model FFMSAdminTool.Views.Home.TestDirectModel
    @{
        Layout = null;
    }
    <!DOCTYPE html>
    <html>
    <head>
        <title>
            Hello World - Ext.NET Examples
        </title>
        
    </head>
    <body>
        <h1>Hello World</h1>
    
        <p>
            The following sample demonstrates how to configure a new Window and <code>show</code> the Window if closed.
        </p>
    
        <ext-button text="Show Window (Client Event)" onClientClick="App.Window1.show();" />
    
        <br />
    
        <ext-button text="Show Window (Direct Event)" onDirectClick="ShowWindowDirect" />
    
        <ext-window id="Window1"
                    title="Hello World"
                    height="270"
                    width="360"
                    bodyPadding="18"
                    modal="true">
            <content>
                This is my first
                <a target="_blank" href="https://ext.net/">Ext.NET</a> Window.
            </content>
        </ext-window>
    </body>
    </html>
    //TestDirect.cshtml.cs
    
    using Ext.Net;
    using Ext.Net.Core;
    using Microsoft.AspNetCore.Mvc.RazorPages;
    using Microsoft.AspNetCore.Mvc;
    
    namespace FFMSAdminTool.Views.Home
    {
        public class TestDirectModel : PageModel
        {
            public void OnGet()
            {
            }
    
            public IActionResult OnPostShowWindowDirect()
            {
                this.GetCmp<Window>("Window1").Show();
    
                return this.Direct();
            }
        }
    }
    Thank you
    Last edited by fabricio.murta; Nov 05, 2020 at 12:18 PM.
  2. #2
    Hello @Geovision! Thanks for trying Ext.NET 7!

    I have tried to recreate the scenario you described with no luck. Even if I created first a directory with Index.cshtml then renamed it to DirectTest.cshtml, also renaming the class name and namespace, the direct event worked.

    I can only suspect some missing or different setting you have in Startup.cs might be causing this. I have tried just commenting or changing some settings but I couldn't make it load the page then break the direct event with a wrong path (404).

    If I can open http://localhost:5000/TestDirect (thus MyProject/Pages/TestDirect.cshtml) it will always be able to trigger the right path to raise and handle the direct event.

    How have you created the project? From VSIX template? dotnet new extnet maybe? I don't really see anything wrong with your code, which is very consistent with the example you pointed.
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Please share your projects Startup.cs file. Before sharing, please remove anything from that file that you feel is confidential, although typically there isn't anything.
    Geoffrey McGill
    Founder
  4. #4
    Hello,

    Please find my startUp.cs page:

    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Builder;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.AspNetCore.HttpsPolicy;
    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.Extensions.Hosting;
    
    using Ext.Net.Core;
    
    namespace FFMSAdminTool
    {
        public class Startup
        {
            public Startup(IConfiguration configuration)
            {
                Configuration = configuration;
            }
    
            public IConfiguration Configuration { get; }
    
            // This method gets called by the runtime. Use this method to add services to the container.
            public void ConfigureServices(IServiceCollection services)
            {
                services.AddControllersWithViews();
                services.AddExtNet();
    
            }
    
            // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
            public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
            {
                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                }
                else
                {
                    app.UseExceptionHandler("/Home/Error");
                    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                    app.UseHsts();
                }
               
                app.UseHttpsRedirection();
    
                app.UseExtNetCore();
                app.UseStaticFiles();
    
                app.UseRouting();
    
                app.UseAuthorization();
    
    
               
                app.UseEndpoints(endpoints =>
                {
                    endpoints.MapControllerRoute(
                        name: "default",
                        pattern: "{controller=Home}/{action=Index}/{id?}");
                });
            }
        }
    }
    Thank you
  5. #5
    Hello again, @Geovision!

    You have either used an old version of the templates or manually created your project, for what I see in your Startup.cs code. I strongly advise you to update your VSIX or dotnet template and re-create the project. There's no telling what else in the project will need to be fixed before it works otherwise.

    It looks like your Startup.cs is based in a prerelease version of Ext.NET, so please re-create the project using a stable release (7.1.0) from one of the supported scenarios. Please check our Ext.NET 7.1 release blog post, in particular the New Ext.NET templates section.

    Let us know if it still doesn't work in your project.

    Anyhow, for reference, this is how a current template's Startup.cs file would look like; maybe just by merging the missing parts with yours it may fix the problems you have; try merging it at your own risk -- it is best to rely on the templates. Since stable was released, they shouldn't break between releases.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using System.IO.Compression;
    using Microsoft.AspNetCore.ResponseCompression;
    using Microsoft.AspNetCore.Builder;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.Extensions.Hosting;
    using Ext.Net;
    using Ext.Net.Core;
    using Westwind.AspNetCore.LiveReload;
    
    namespace ExtNetProject
    {
        public class Startup
        {
            public Startup(IConfiguration configuration)
            {
                Configuration = configuration;
            }
    
            public IConfiguration Configuration { get; }
    
            // This method gets called by the runtime. Use this method to add services to the container.
            public void ConfigureServices(IServiceCollection services)
            {
                services.Configure<GzipCompressionProviderOptions>(options =>
                {
                    options.Level = System.IO.Compression.CompressionLevel.Optimal;
                });
    
                services.AddResponseCompression(options =>
                {
                    options.EnableForHttps = true;
                    options.Providers.Add<GzipCompressionProvider>();
    
                    options.MimeTypes = new[]
                    {
                        "text/css",
                        "application/javascript",
                        "application/json",
                        "text/json",
                        "application/xml",
                        "text/xml",
                        "text/plain",
                        "image/svg+xml",
                        "application/x-font-ttf"
                    };
                });
    
                services.AddRazorPages().AddRazorRuntimeCompilation();
    
                // See https://github.com/RickStrahl/Westwind.AspnetCore.LiveReload
                services.AddLiveReload();
    
                // 1. Register Ext.NET services
                services.AddExtNet();
                services.AddExtCharts();
            }
    
            // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
            public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
            {
                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                    app.UseLiveReload();
                }
                else
                {
                    app.UseExceptionHandler("/Error");
                }
    
                app.UseResponseCompression();
    
                // 2. Use Ext.NET resources
                //    To be added prior to app.UseStaticFiles()
                app.UseExtNetResources(config =>
                {
                    if (env.IsDevelopment())
                    {
                        config.UseDebug(true);
                    }
    
                    config.UseEmbedded();
                    config.UseCharts();
                    config.UseThemeSpotless();
                });
    
                // 3. Enable Ext.NET localization [not required]
                //    If included, localization will be handled automatically
                //    based on client browser preferences
                app.UseExtNetLocalization();
    
                app.UseStaticFiles();
                app.UseRouting();
                app.UseAuthorization();
    
                // 4. Ext.NET middleware
                //    To be added prior to app.UseEndpoints()
                app.UseExtNet(config =>
                {
                    config.Theme = ThemeKind.Spotless;
                });
    
                app.UseEndpoints(endpoints => endpoints.MapRazorPages());
            }
        }
    }
    Hope this helps!

    Edit: check out supported installation means at our Getting Started guide's Installation Options section!
    Last edited by fabricio.murta; Nov 04, 2020 at 6:44 PM.
  6. #6
    Dear,

    I followed up the guide and it is working now.

    Thank you.

Similar Threads

  1. Hide Mask during Direct Method Call
    By dkhandelwal in forum 2.x Help
    Replies: 1
    Last Post: May 04, 2016, 2:36 PM
  2. Replies: 0
    Last Post: May 28, 2013, 2:51 PM
  3. [CLOSED] Output Cache issue with Direct Method / Direct Event
    By amitpareek in forum 1.x Legacy Premium Help
    Replies: 18
    Last Post: Mar 01, 2013, 5:03 AM
  4. [CLOSED] how to call direct method
    By tactime10 in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Oct 04, 2012, 8:38 AM
  5. how to call direct method in asp.net mvc3
    By waqasde in forum 2.x Help
    Replies: 1
    Last Post: Mar 16, 2012, 9:26 AM

Posting Permissions