Chuyển đến nội dung
Skillpedia
Website và giao diện (frontend)5.8k · #14565

create-blazor-project

Skill này làm gì

Skill này tạo một ứng dụng web Blazor mới và giúp bạn chọn mức tương tác của nó. Skill dành cho lập trình viên .NET bắt đầu một trang hoặc ứng dụng Blazor mới.

Khi nào nên dùng

  • ✓Khi bạn muốn bắt đầu một ứng dụng web Blazor mới.
  • ✓Khi bạn cần chọn giữa tương tác tĩnh, server và WebAssembly.
  • ✓Khi bạn muốn một dự án mới được khởi tạo với các tùy chọn phù hợp.

Liên kết skill

https://github.com/dotnet/skills/blob/main/plugins/dotnet-blazor/skills/create-blazor-project/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/dotnet/skills/blob/main/plugins/dotnet-blazor/skills/create-blazor-project/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Tạo một ứng dụng web Blazor mới cho danh mục sản phẩm của tôi, có tìm kiếm và giỏ hàng, dùng mức tương tác đơn giản nhất phù hợp.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent hỏi về tính năng và nhu cầu tương tác của ứng dụng, chọn chế độ render đơn giản nhất phù hợp, rồi tạo dự án với các tùy chọn tương ứng.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Create a Blazor Web App

Before You Start — Gather Requirements

If the user's request doesn't make the following clear, ask before scaffolding:

  1. What does the app do? List the main screens/features (e.g., "product catalog with search and shopping cart").
  2. What kind of interactivity is needed? Displaying data and forms? Real-time updates? Offline support? Rich drag-and-drop UI?
  3. Deployment environment? Internet-facing? Intranet? Mobile users on slow connections?
  4. Authentication needed? Anonymous? Individual accounts? Organizational (Azure AD)?

Pick the Right Interactivity Level

Blazor render modes are a progression scale. Start at the simplest level that satisfies the requirements and only move up when there's a concrete reason.

Static SSR ──→ SSR + Enhanced Nav ──→ Interactive Server ──→ Interactive WebAssembly
 simplest                                                           most complex

Decision Rules

If the app needs... Use Why
Display data, simple forms, links between pages Static SSR (-int None) No JS runtime, no circuit, no WebAssembly download. Forms work via HTML POST. Enhanced navigation makes it feel snappy.
Everything above + a few components with client-side behavior (live search, real-time updates, complex form wizards) Interactive Server, per-page (-int Server) Only the components that need interactivity opt in with @rendermode. The rest stays static. Server-side execution, full .NET access, no API layer needed.
Most pages need rich interactivity (dashboards, drag-and-drop, chat) Interactive Server, global (-int Server -ai) Every component is interactive by default. Consistent UX, simpler mental model. Trade-off: every user holds a SignalR circuit on the server.
Network latency is a problem, users are on mobile/poor connections, or the app must work offline Interactive WebAssembly (-int WebAssembly) Code runs in the browser. Eliminates round-trip latency but requires a .Client project, API layer for data access, and downloads the .NET runtime to the browser on first visit. For offline support, enable PWA: add a service worker and manifest after scaffolding (not included in the template by default).
Fast initial load (Server) + low latency after (WebAssembly) Interactive Auto (-int Auto) First visit uses Server; subsequent visits use cached WebAssembly runtime. Most complex setup — see Auto constraints below. Only choose when both Server and WebAssembly constraints apply.

Default recommendation: Start with -int Server (per-page). It covers the vast majority of apps. Upgrade to global or WebAssembly only when a specific requirement demands it.

Auto Mode Constraints

Auto mode means your component code runs on the server first, then in the browser on subsequent visits. This creates real constraints:

  • All interactive components must live in the .Client project — same as WebAssembly.
  • No direct server access from interactive components — no EF DbContext, no file system, no server-only services. All data access must go through HTTP APIs.
  • Both Program.cs files must register matching services — the server and client DI containers must both provide implementations for any service an interactive component injects.
  • Code must not assume its execution environment — no HttpContext access, no browser-only APIs without RendererInfo guards.
  • Test in both modes — a component that works on Server during development may break on WebAssembly in production (second visit). Test both paths.

Don'ts

  • Don't pick WebAssembly "because it's cool" — it adds a .Client project, forces API-mediated data access, and downloads ~10MB to the browser on first visit.
  • Don't pick Auto unless you can articulate why Server alone and WebAssembly alone are both insufficient.
  • Don't pick global interactivity for apps where most pages are read-only content — per-page keeps the static pages fast and reduces server memory.

Scaffold the Project

Static SSR Only (display data + simple forms)

dotnet new blazor -o {AppName} -int None

No interactive runtime. Enhanced navigation enabled by default via blazor.web.js.

Interactive Server, Per-Page (recommended default)

dotnet new blazor -o {AppName} -int Server

Pages are static by default. Add @rendermode InteractiveServer to components that need interactivi

Câu hỏi thường gặp

Có những lựa chọn tương tác nào?

Render tĩnh phía server, tương tác phía server, tương tác WebAssembly và chế độ tự động.

Skill có bắt đầu với lựa chọn đơn giản nhất không?

Có. Skill bắt đầu ở mức đơn giản nhất và chỉ nâng cấp khi có lý do rõ ràng.

Skill có thêm tính năng cho dự án hiện có không?

Không. Skill dành cho việc tạo dự án mới, còn dự án hiện có được xử lý ở nơi khác.

Chi tiết

Mô tả gốc của tác giả

Create a new ASP.NET Core web application or web site using Blazor. USE FOR: creating a new Blazor web app, scaffolding a new web project, starting a new web site, choosing render modes (Static SSR, Interactive Server, Interactive WebAssembly, Auto), running dotnet new blazor with the right options, setting up initial project structure. DO NOT USE FOR: adding features to existing projects, changing how an existing app renders, or component authoring (use author-component).

repo: dotnet/skills

Độ phổ biến

Sao GitHub
5.8k
Vị trí xếp hạng
#14565
Giấy phép
MIT
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự