PDA

View Full Version : [CLOSED] EXT.NET 7.0 Core - Direct Method Handler/Call Issue



Geovision
Nov 03, 2020, 3:15 PM
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 ()

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

fabricio.murta
Nov 03, 2020, 5:29 PM
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.

geoffrey.mcgill
Nov 03, 2020, 6:33 PM
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.

Geovision
Nov 04, 2020, 5:54 AM
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

fabricio.murta
Nov 04, 2020, 6:41 PM
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 (https://ext.net/ext-net-classic-7-1-with-new-partial-and-section/), 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().AddRazorRuntimeCompilatio n();

// 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 (https://docs.ext.net/guides/getting_started/#installation-options)!

Geovision
Nov 05, 2020, 7:09 AM
Dear,

I followed up the guide and it is working now.

Thank you.

fabricio.murta
Nov 05, 2020, 1:18 PM
Glad it worked out, thanks for the feedback!