Skip to content

Commit 6f2d1ba

Browse files
Fix ASP.NET Core (#35)
* remove old project * add new project
1 parent 5dd0dec commit 6f2d1ba

25 files changed

+5220
-215
lines changed

ASP.NET Core/ASP.NET Core.csproj

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<Target Name="DebugEnsureNodeEnv" BeforeTargets="BeforeBuild" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">
8+
<!-- Ensure Node.js is installed -->
9+
<Exec Command="node --version" ContinueOnError="true">
10+
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
11+
</Exec>
12+
<Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />
13+
<Message Importance="high" Text="Restoring dependencies using 'npm'. This may take several minutes..." />
14+
<Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
15+
</Target>
16+
<Target Name="RunGulp" BeforeTargets="BeforeBuild" Condition=" '$(Configuration)' == 'Debug' And Exists('$(SpaRoot)node_modules') ">
17+
<Exec WorkingDirectory="$(ProjectDir)" Command="node_modules\.bin\gulp add-resources" ContinueOnError="false">
18+
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
19+
</Exec>
20+
</Target>
21+
22+
<ItemGroup>
23+
<PackageReference Include="DevExtreme.AspNet.Core" Version="25.1.3" />
24+
</ItemGroup>
25+
26+
</Project>
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.28307.329
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30330.147
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CascadingSelectBoxesSample", "CascadingSelectBoxesSample\CascadingSelectBoxesSample.csproj", "{7B3C3E1C-1522-4587-B2A7-22AB45EE5478}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ASP.NET Core", "ASP.NET Core.csproj", "{435CB7A8-3168-4BD2-815F-E54F708AF968}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1010
Debug|Any CPU = Debug|Any CPU
1111
Release|Any CPU = Release|Any CPU
1212
EndGlobalSection
1313
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14-
{7B3C3E1C-1522-4587-B2A7-22AB45EE5478}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15-
{7B3C3E1C-1522-4587-B2A7-22AB45EE5478}.Debug|Any CPU.Build.0 = Debug|Any CPU
16-
{7B3C3E1C-1522-4587-B2A7-22AB45EE5478}.Release|Any CPU.ActiveCfg = Release|Any CPU
17-
{7B3C3E1C-1522-4587-B2A7-22AB45EE5478}.Release|Any CPU.Build.0 = Release|Any CPU
14+
{435CB7A8-3168-4BD2-815F-E54F708AF968}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{435CB7A8-3168-4BD2-815F-E54F708AF968}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{435CB7A8-3168-4BD2-815F-E54F708AF968}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{435CB7A8-3168-4BD2-815F-E54F708AF968}.Release|Any CPU.Build.0 = Release|Any CPU
1818
EndGlobalSection
1919
GlobalSection(SolutionProperties) = preSolution
2020
HideSolutionNode = FALSE
2121
EndGlobalSection
2222
GlobalSection(ExtensibilityGlobals) = postSolution
23-
SolutionGuid = {39C49DA1-8082-435B-A431-60B10AADB5A8}
23+
SolutionGuid = {08AFB133-D1F6-4FE9-A66A-586B96B002D0}
2424
EndGlobalSection
2525
EndGlobal

NetCore/CascadingSelectBoxesSample/Controllers/HomeController.cs renamed to ASP.NET Core/Controllers/HomeController.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Threading.Tasks;
55
using Microsoft.AspNetCore.Mvc;
66

7-
namespace CascadingSelectBoxesSample.Controllers
7+
namespace ASP_NET_Core.Controllers
88
{
99
public class HomeController : Controller
1010
{
@@ -13,5 +13,9 @@ public IActionResult Index()
1313
return View();
1414
}
1515

16+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
17+
public IActionResult Error() {
18+
return View();
19+
}
1620
}
1721
}

NetCore/CascadingSelectBoxesSample/Models/Address.cs renamed to ASP.NET Core/Models/Address.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Linq;
44
using System.Threading.Tasks;
55

6-
namespace CascadingSelectBoxesSample.Models
6+
namespace ASP_NET_Core.Models
77
{
88
public class Address
99
{

NetCore/CascadingSelectBoxesSample/Models/City.cs renamed to ASP.NET Core/Models/City.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
using System.Text;
55
using System.Threading.Tasks;
66

7-
namespace CascadingSelectBoxesSample.Models {
7+
namespace ASP_NET_Core.Models {
88
public class City
99
{
1010
public int ID { get; set; }
1111
public int StateID { get; set; }
1212
public string Name { get; set; }
1313

14-
public static City[] Cities = new City[] {
14+
public static City[] Cities = [
1515
new City() {
1616
ID = 1,
1717
Name = "Tuscaloosa",
@@ -93,6 +93,6 @@ public class City
9393
Name = "Ontario",
9494
StateID = 5
9595
}
96-
};
96+
];
9797
}
9898
}

NetCore/CascadingSelectBoxesSample/Models/State.cs renamed to ASP.NET Core/Models/State.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
using System.Text;
55
using System.Threading.Tasks;
66

7-
namespace CascadingSelectBoxesSample.Models {
7+
namespace ASP_NET_Core.Models {
88
public class State
99
{
1010
public int ID { get; set; }
1111
public string Name { get; set; }
1212

13-
public static State[] States = new State[] {
13+
public static State[] States = [
1414
new State() {
1515
ID = 1,
1616
Name = "Alabama"
@@ -31,6 +31,6 @@ public class State
3131
ID = 5,
3232
Name = "California"
3333
}
34-
};
34+
];
3535
}
3636
}

ASP.NET Core/Program.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.Extensions.DependencyInjection;
3+
using Microsoft.Extensions.Hosting;
4+
5+
namespace ASP_NET_Core {
6+
public class Program {
7+
public static void Main(string[] args) {
8+
var builder = WebApplication.CreateBuilder(args);
9+
10+
// Add services to the container.
11+
builder.Services
12+
.AddControllersWithViews()
13+
.AddJsonOptions(options => options.JsonSerializerOptions.PropertyNamingPolicy = null);
14+
15+
var app = builder.Build();
16+
17+
// Configure the HTTP request pipeline.
18+
if (app.Environment.IsDevelopment()) {
19+
app.UseDeveloperExceptionPage();
20+
} else {
21+
app.UseExceptionHandler("/Home/Error");
22+
}
23+
24+
app.UseStaticFiles();
25+
26+
app.UseRouting();
27+
28+
app.UseAuthorization();
29+
30+
app.MapControllerRoute(
31+
name: "default",
32+
pattern: "{controller=Home}/{action=Index}/{id?}"
33+
);
34+
35+
app.Run();
36+
}
37+
}
38+
}

ASP.NET Core/Readme.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# ASP.NET Core DevExtreme Example
2+
3+
## Installation
4+
5+
Download the example and use Visual Studio 2022 (or later) or Visual Studio Code to open the project. This project targets .NET 8.0.
6+
7+
## Client-side resources and bundling
8+
9+
This project uses [NPM](https://www.npmjs.com/) and [Gulp.js](https://gulpjs.com/) to install client-side libraries. The project restores NPM packages before the first build. Then, Gulp bundles required scripts and CSS files into the resulting package during the first and every next build.
10+
11+
The project includes:
12+
- DevExtreme 24.2.3
13+
- DevExtreme.AspNet.Core 24.2.*
14+
- DevExtreme.AspNet.Data 5.*
15+
- jQuery 3.7.1
16+
- Bootstrap 5.3.3
17+
18+
The resulted bundles will be located in the `wwwroot` folder:
19+
* `css/vendor.css` - a file with all CSS styles.
20+
* `css/icons` and `css/fonts` - folders that contain fonts and icons for DevExtreme themes.
21+
* `js/vendor.js` - a file that contains all scripts.
22+
23+
The default bundle includes jQuery, Bootstrap, and DevExtreme.
24+
25+
### Add more 3rd-party libraries for additional features/components
26+
27+
The main logic is located in the the `gulpfile.js` file at the root application level. The file contains two tasks:
28+
29+
* the `add-resources` task
30+
31+
* copies JavaScript files located in the `scripts` array and adds them to `vendor.js`. The script bundle is moved to `wwwroot\js`.
32+
* copies CSS styles located in the `styles` array and merges them into the `vendor.css` bundle. Then, this bundle is moved to `wwwroot\css`
33+
* copies DevExtreme `fonts` and `icons` folders from NPM to `wwwroot\css`
34+
35+
* the `clean` task removes all previously created files (`vendor.js` and `vendor.css`) and folders (`icons` and `fonts`)
36+
37+
If you need to include more features, you can uncomment one of the following sections:
38+
39+
* Gantt - scripts and styles for [dxGantt](https://js.devexpress.com/DevExtreme/Guide/UI_Components/Gantt/Getting_Started_with_Gantt/).
40+
* Diagram - scripts and styles for [dxDiagram](https://js.devexpress.com/DevExtreme/Guide/UI_Components/Diagram/Getting_Started_with_Diagram/).
41+
* Export - scripts and styles for the exporting feature: [Export Data to Excel](https://js.devexpress.com/DevExtreme/Guide/UI_Components/DataGrid/Getting_Started_with_DataGrid/#Export_Data).
42+
* HtmlEditor - scripts and styles for [dxHtmlEditor](https://js.devexpress.com/DevExtreme/Guide/UI_Components/HtmlEditor/Overview/).
43+
* Full Bundle - scripts and styles for all above mentioned features/components.
44+
45+
## Code
46+
47+
Take a look at the following files of this example to see the required code:
48+
49+
**Controllers:**
50+
- `Controllers/HomeController.cs` - Main controller with Index action
51+
- `Controllers/SampleDataController.cs` - API controller for sample data
52+
53+
**Models:**
54+
- `Models/SampleData.cs` - Sample data model
55+
- `Models/SampleOrder.cs` - Sample order model
56+
57+
**Views:**
58+
- `Views/Home/Index.cshtml` - Main page with DevExtreme components
59+
- `Views/Shared/_Layout.cshtml` - Layout template
60+
- `Views/_ViewImports.cshtml` - Global imports
61+
- `Views/_ViewStart.cshtml` - View start configuration
62+
63+
**Configuration:**
64+
- `Program.cs` - Application entry point
65+
- `Startup.cs` - Service configuration
66+
- `gulpfile.js` - Build automation
67+
- `package.json` - NPM dependencies
68+
- `ASP.NET Core.csproj` - Project file
69+
70+
## Development server
71+
72+
Use the Visual Studio `Run (F5)` command or `dotnet run` command to run the project. The application will be available at `https://localhost:5001` (HTTPS) or `http://localhost:5000` (HTTP).
73+
74+
## Further help
75+
76+
You can learn more about the ASP.NET Core components' syntax in our documentation: [Concepts](https://docs.devexpress.com/AspNetCore/400574/devextreme-based-controls/concepts/razor-syntax)
77+
The client-side API is based on jQuery [jQuery documentation](https://api.jquery.com/) and described in the following topics:
78+
* [Get and Set Properties](https://js.devexpress.com/DevExtreme/Guide/jQuery_Components/Component_Configuration_Syntax/#Get_and_Set_Properties)
79+
* [Call Methods](https://js.devexpress.com/DevExtreme/Guide/jQuery_Components/Component_Configuration_Syntax/#Call_Methods)
80+
* [Get a UI Component Instance](https://js.devexpress.com/DevExtreme/Guide/jQuery_Components/Component_Configuration_Syntax/#Get_a_UI_Component_Instance)
81+
82+
To get more help on DevExtreme submit an issue in the [Support Center](https://supportcenter.devexpress.com/ticket/create)
83+
84+

NetCore/CascadingSelectBoxesSample/Views/Home/Index.cshtml renamed to ASP.NET Core/Views/Home/Index.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@using CascadingSelectBoxesSample.Models
1+
@using ASP_NET_Core.Models
22

33
<script>
44
function onValueChanged(e) {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<h2>An error occurred while the server was processing your request.</h2>
2+
3+
<p>
4+
To display detailed information about the error, set the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong> and restart the app.
5+
</p>
6+
<p>
7+
<strong>The Development environment should not be enabled for deployed applications</strong> because it provides users access to exceptions that can contain sensitive information.
8+
</p>

0 commit comments

Comments
 (0)