Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions ASP.NET Core/ASP.NET Core.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<Target Name="DebugEnsureNodeEnv" BeforeTargets="BeforeBuild" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">
<!-- Ensure Node.js is installed -->
<Exec Command="node --version" ContinueOnError="true">
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
</Exec>
<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." />
<Message Importance="high" Text="Restoring dependencies using 'npm'. This may take several minutes..." />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
</Target>
<Target Name="RunGulp" BeforeTargets="BeforeBuild" Condition=" '$(Configuration)' == 'Debug' And Exists('$(SpaRoot)node_modules') ">
<Exec WorkingDirectory="$(ProjectDir)" Command="node_modules\.bin\gulp add-resources" ContinueOnError="false">
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
</Exec>
</Target>

<ItemGroup>
<PackageReference Include="DevExtreme.AspNet.Core" Version="25.1.3" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.329
# Visual Studio Version 16
VisualStudioVersion = 16.0.30330.147
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CascadingSelectBoxesSample", "CascadingSelectBoxesSample\CascadingSelectBoxesSample.csproj", "{7B3C3E1C-1522-4587-B2A7-22AB45EE5478}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ASP.NET Core", "ASP.NET Core.csproj", "{435CB7A8-3168-4BD2-815F-E54F708AF968}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7B3C3E1C-1522-4587-B2A7-22AB45EE5478}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7B3C3E1C-1522-4587-B2A7-22AB45EE5478}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7B3C3E1C-1522-4587-B2A7-22AB45EE5478}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B3C3E1C-1522-4587-B2A7-22AB45EE5478}.Release|Any CPU.Build.0 = Release|Any CPU
{435CB7A8-3168-4BD2-815F-E54F708AF968}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{435CB7A8-3168-4BD2-815F-E54F708AF968}.Debug|Any CPU.Build.0 = Debug|Any CPU
{435CB7A8-3168-4BD2-815F-E54F708AF968}.Release|Any CPU.ActiveCfg = Release|Any CPU
{435CB7A8-3168-4BD2-815F-E54F708AF968}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {39C49DA1-8082-435B-A431-60B10AADB5A8}
SolutionGuid = {08AFB133-D1F6-4FE9-A66A-586B96B002D0}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace CascadingSelectBoxesSample.Controllers
namespace ASP_NET_Core.Controllers
{
public class HomeController : Controller
{
Expand All @@ -13,5 +13,9 @@ public IActionResult Index()
return View();
}

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error() {
return View();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Linq;
using System.Threading.Tasks;

namespace CascadingSelectBoxesSample.Models
namespace ASP_NET_Core.Models
{
public class Address
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
using System.Text;
using System.Threading.Tasks;

namespace CascadingSelectBoxesSample.Models {
namespace ASP_NET_Core.Models {
public class City
{
public int ID { get; set; }
public int StateID { get; set; }
public string Name { get; set; }

public static City[] Cities = new City[] {
public static City[] Cities = [
new City() {
ID = 1,
Name = "Tuscaloosa",
Expand Down Expand Up @@ -93,6 +93,6 @@ public class City
Name = "Ontario",
StateID = 5
}
};
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
using System.Text;
using System.Threading.Tasks;

namespace CascadingSelectBoxesSample.Models {
namespace ASP_NET_Core.Models {
public class State
{
public int ID { get; set; }
public string Name { get; set; }

public static State[] States = new State[] {
public static State[] States = [
new State() {
ID = 1,
Name = "Alabama"
Expand All @@ -31,6 +31,6 @@ public class State
ID = 5,
Name = "California"
}
};
];
}
}
38 changes: 38 additions & 0 deletions ASP.NET Core/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace ASP_NET_Core {
public class Program {
public static void Main(string[] args) {
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services
.AddControllersWithViews()
.AddJsonOptions(options => options.JsonSerializerOptions.PropertyNamingPolicy = null);

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment()) {
app.UseDeveloperExceptionPage();
} else {
app.UseExceptionHandler("/Home/Error");
}

app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}"
);

app.Run();
}
}
}
84 changes: 84 additions & 0 deletions ASP.NET Core/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# ASP.NET Core DevExtreme Example

## Installation

Download the example and use Visual Studio 2022 (or later) or Visual Studio Code to open the project. This project targets .NET 8.0.

## Client-side resources and bundling

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.

The project includes:
- DevExtreme 24.2.3
- DevExtreme.AspNet.Core 24.2.*
- DevExtreme.AspNet.Data 5.*
- jQuery 3.7.1
- Bootstrap 5.3.3

The resulted bundles will be located in the `wwwroot` folder:
* `css/vendor.css` - a file with all CSS styles.
* `css/icons` and `css/fonts` - folders that contain fonts and icons for DevExtreme themes.
* `js/vendor.js` - a file that contains all scripts.

The default bundle includes jQuery, Bootstrap, and DevExtreme.

### Add more 3rd-party libraries for additional features/components

The main logic is located in the the `gulpfile.js` file at the root application level. The file contains two tasks:

* the `add-resources` task

* copies JavaScript files located in the `scripts` array and adds them to `vendor.js`. The script bundle is moved to `wwwroot\js`.
* copies CSS styles located in the `styles` array and merges them into the `vendor.css` bundle. Then, this bundle is moved to `wwwroot\css`
* copies DevExtreme `fonts` and `icons` folders from NPM to `wwwroot\css`

* the `clean` task removes all previously created files (`vendor.js` and `vendor.css`) and folders (`icons` and `fonts`)

If you need to include more features, you can uncomment one of the following sections:

* Gantt - scripts and styles for [dxGantt](https://js.devexpress.com/DevExtreme/Guide/UI_Components/Gantt/Getting_Started_with_Gantt/).
* Diagram - scripts and styles for [dxDiagram](https://js.devexpress.com/DevExtreme/Guide/UI_Components/Diagram/Getting_Started_with_Diagram/).
* 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).
* HtmlEditor - scripts and styles for [dxHtmlEditor](https://js.devexpress.com/DevExtreme/Guide/UI_Components/HtmlEditor/Overview/).
* Full Bundle - scripts and styles for all above mentioned features/components.

## Code

Take a look at the following files of this example to see the required code:

**Controllers:**
- `Controllers/HomeController.cs` - Main controller with Index action
- `Controllers/SampleDataController.cs` - API controller for sample data

**Models:**
- `Models/SampleData.cs` - Sample data model
- `Models/SampleOrder.cs` - Sample order model

**Views:**
- `Views/Home/Index.cshtml` - Main page with DevExtreme components
- `Views/Shared/_Layout.cshtml` - Layout template
- `Views/_ViewImports.cshtml` - Global imports
- `Views/_ViewStart.cshtml` - View start configuration

**Configuration:**
- `Program.cs` - Application entry point
- `Startup.cs` - Service configuration
- `gulpfile.js` - Build automation
- `package.json` - NPM dependencies
- `ASP.NET Core.csproj` - Project file

## Development server

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).

## Further help

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)
The client-side API is based on jQuery [jQuery documentation](https://api.jquery.com/) and described in the following topics:
* [Get and Set Properties](https://js.devexpress.com/DevExtreme/Guide/jQuery_Components/Component_Configuration_Syntax/#Get_and_Set_Properties)
* [Call Methods](https://js.devexpress.com/DevExtreme/Guide/jQuery_Components/Component_Configuration_Syntax/#Call_Methods)
* [Get a UI Component Instance](https://js.devexpress.com/DevExtreme/Guide/jQuery_Components/Component_Configuration_Syntax/#Get_a_UI_Component_Instance)

To get more help on DevExtreme submit an issue in the [Support Center](https://supportcenter.devexpress.com/ticket/create)


Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@using CascadingSelectBoxesSample.Models
@using ASP_NET_Core.Models

<script>
function onValueChanged(e) {
Expand Down
8 changes: 8 additions & 0 deletions ASP.NET Core/Views/Shared/Error.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<h2>An error occurred while the server was processing your request.</h2>

<p>
To display detailed information about the error, set the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong> and restart the app.
</p>
<p>
<strong>The Development environment should not be enabled for deployed applications</strong> because it provides users access to exceptions that can contain sensitive information.
</p>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!DOCTYPE html>

<html>
<head>
Expand All @@ -8,21 +8,21 @@
<meta name="description" content="">
<meta name="author" content="">

<title>ASP.NET Core - Standalone and in-Form cascading SelectBoxes</title>
<title>ASP_NET_Core</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />

@* Uncomment to use the HtmlEditor control *@
@* <script src="https://cdnjs.cloudflare.com/ajax/libs/quill/1.3.6/quill.min.js"></script> *@
@* <script src="https://unpkg.com/devextreme-quill/dist/dx-quill.min.js"></script> *@

<link rel="stylesheet" href="~/css/vendor.css" asp-append-version="true" />
<link rel="stylesheet" href="~/css/Site.css" />
<script src="~/js/vendor.js" asp-append-version="true"></script>
</head>

<body>
<main role="main" class="container">
<body class="dx-viewport">
<div class="demo-container">
@RenderBody()
</main>
</div>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@using CascadingSelectBoxesSample
@using ASP_NET_Core
@namespace ASP_NET_Core.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@using DevExtreme.AspNet.Mvc
9 changes: 9 additions & 0 deletions ASP.NET Core/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
10 changes: 10 additions & 0 deletions ASP.NET Core/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
Loading