Browse Source

Introduce `abp generate-razor-page` command.

Close #20998
pull/21017/head
maliming 1 year ago
parent
commit
2e6239dd93
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 115
      docs/en/cli/index.md
  2. BIN
      docs/en/images/abp-generate-razor-page.png

115
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; }
}
<html lang="@HtmlEncoder.Encode(CultureInfo.CurrentCulture.Name)">
<head>
<meta charset="utf-8" />
<style>
<%$ include: MyPage.css %>
</style>
<title>@HtmlEncoder.Encode(Model.Message)</title>
</head>
<body>
<h3>@HtmlEncoder.Encode(Model.Message)</h3>
<ul class="list-group">
@for(int i = 0; i < 10; i++)
{
<li class="list-group-item">@i item</li>
}
</ul>
<script>
//<!--
<%$ include: MyPage.js %>
//-->
</script>
</body>
</html>
```
```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.

BIN
docs/en/images/abp-generate-razor-page.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 KiB

Loading…
Cancel
Save