diff --git a/docs/en/cli/index.md b/docs/en/cli/index.md index 3fd8eee2f4..334e17e0d1 100644 --- a/docs/en/cli/index.md +++ b/docs/en/cli/index.md @@ -70,6 +70,7 @@ Here, is the list of all available commands before explaining their details: * **`clear-download-cache`**: Clears the templates download cache. * **`check-extensions`**: Checks the latest version of the ABP CLI extensions. * **`install-old-cli`**: Installs old ABP CLI. +* **`generate-razor-page`**: Generate a page class and then use it in the ASP NET Core pipeline to return an HTML page. ### help @@ -964,6 +965,120 @@ Usage: abp install-old-cli [options] ``` +### generate-razor-page + +`generate-razor-page` command to generate a page class and then use it in the ASP NET Core pipeline to return an HTML page. + +Usage: + +1. Create a new `Razor Page(MyPage.cshtml)` that inherits from `AbpCompilationRazorPageBase` in `Views` folder. +2. Create a `MyPageModel` class in the same folder. +2. Create a `MyPage.js` and `MyPage.css` files in the same folder. +3. Add the following code to the `MyPage.cshtml`, `MyPage.css` and `MyPage.js` files. +4. Run the `generate-razor-page` command under the `Views` folder. + +```cs +public class MyPageModel +{ + public string Message { get; set; } + + public MyPageModel(string message) + { + Message = message; + } +} +``` + +```cs +@using System.Globalization +@using Volo.Abp.AspNetCore.MultiTenancy.Views +@using Volo.Abp.AspNetCore.RazorViews +@inherits AbpCompilationRazorPageBase +@{ + Response.ContentType = "text/html; charset=utf-8"; + Response.StatusCode = 200; +} + +@functions{ + public MyPage(MyPageModel model) + { + Model = model; + } + + public MyPageModel Model { get; set; } +} + + + + + + @HtmlEncoder.Encode(Model.Message) + + +

@HtmlEncoder.Encode(Model.Message)

+ + + + + + +``` + +```css +body { + background-color: #65b2ff; + color: #495057; + font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; +} +``` + +```js +console.log('MyPage.js loaded!'); +``` + +The command output will be: + +```bash +> abp generate-razor-page + +Generating code files for pages in /MyProject/Views + Generating code file for page MyPage.cshtml ... + Inlining file MyPage.css + Inlining file MyPage.js + Done! +1 files successfully generated. +``` + +The `MyPage.Designer.cs` file will be created in the same folder, it's a standard C# class you can use it in the pipeline to return an HTML page. + +```cs +app.Use(async (httpContext, next) => +{ + if (true) // Your condition + { + var page = new MyPage(new MyPageModel("Test message")); + await page.ExecuteAsync(httpContext); + } + else + { + await next(); + } +}); +``` + +![Razor Page](./../images/abp-generate-razor-page.png) + #### Options * ```--version``` or ```-v```: Specifies the version for ABP CLI to be installed. diff --git a/docs/en/images/abp-generate-razor-page.png b/docs/en/images/abp-generate-razor-page.png new file mode 100644 index 0000000000..b113e0604e Binary files /dev/null and b/docs/en/images/abp-generate-razor-page.png differ