Skip to content
| Marketplace
Sign in
Visual Studio Code>Snippets>sarthiNew to Visual Studio Code? Get it now.
sarthi

sarthi

hppatel

|
1 install
| (0) | Free
Professional ASP.NET MVC code snippets for C# — controllers, repositories, interfaces, DI, CRUD, models, services, LINQ, and validation patterns.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

ASP.NET MVC Snippets

Version Installs License

Professional, production-ready ASP.NET MVC code snippets for C# — scaffolding controllers, repositories, services, models, LINQ queries, and more in seconds.


✨ Features

  • 12 carefully crafted snippets covering the full MVC/Clean Architecture stack
  • Works exclusively in .cs (C#) files — no accidental triggering
  • Follows ASP.NET Core best practices: null guards, async/await, AsNoTracking, and structured logging
  • Every snippet uses tab stops so you can fill in your entity name once and propagate it throughout
  • Covers the complete vertical slice: Controller → Service → Repository → DbContext → Model/DTO

📦 Installation

From VS Code Marketplace

  1. Open VS Code
  2. Press Ctrl+P (or Cmd+P on macOS)
  3. Type ext install your-publisher-name.aspnet-mvc-snippets
  4. Press Enter

From the Extensions panel

  1. Click the Extensions icon in the Activity Bar (Ctrl+Shift+X)
  2. Search for ASP.NET MVC Snippets
  3. Click Install

Manual (VSIX)

  1. Download the latest .vsix from GitHub Releases
  2. In VS Code: Extensions → ... menu → Install from VSIX…
  3. Select the downloaded file

🚀 Usage

  1. Open any .cs file in your ASP.NET project
  2. Type a snippet prefix (e.g. mvc-controller)
  3. Select the suggestion from IntelliSense or press Tab
  4. Fill in the first tab stop (usually your entity name) — it auto-propagates
  5. Press Tab to advance through remaining placeholders

Tip: All tab stops are ordered so that typing your entity name once fills it in everywhere it appears.


📋 Snippet Reference

Prefix What it generates
mvc-controller Full API controller with GET/POST/PUT/DELETE, DI, and logging
mvc-interface Typed repository interface with async CRUD signatures
mvc-repository EF Core repository implementation (CRUD + AsNoTracking)
mvc-di DI constructor with null guards and ILogger
mvc-action Single async IActionResult method with HTTP verb picker
mvc-crud CRUD service methods with DTO mapping helpers
mvc-model Entity class with Data Annotations and audit fields
mvc-service Service interface + implementation with logging
mvc-linq Common EF Core LINQ patterns (filter, project, paginate, include)
mvc-validation DTO class with full Data Annotations validation
mvc-dbcontext DbContext with DbSet and Fluent API configuration
mvc-program Complete Program.cs service registration block
mvc-middleware Global exception handling middleware with JSON response

🖥️ Example — Scaffold a Feature in Under 2 Minutes

1. Model (mvc-model)

[Table("Products")]
public class Product
{
    [Key]
    public int Id { get; set; }

    [Required]
    [StringLength(200)]
    public string Name { get; set; } = string.Empty;

    public bool IsActive { get; set; } = true;
    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
    public DateTime? UpdatedAt { get; set; }
}

2. Repository Interface (mvc-interface)

public interface IProductRepository
{
    Task<IEnumerable<Product>> GetAllAsync();
    Task<Product?> GetByIdAsync(int id);
    Task<Product> AddAsync(Product entity);
    Task<Product?> UpdateAsync(Product entity);
    Task<bool> DeleteAsync(int id);
    Task<bool> ExistsAsync(int id);
}

3. Repository (mvc-repository)

public class ProductRepository : IProductRepository
{
    private readonly AppDbContext _context;
    // ... full EF Core implementation
}

4. Service (mvc-service)

public class ProductService : IProductService
{
    private readonly IProductRepository _repository;
    private readonly ILogger<ProductService> _logger;
    // ... full service implementation
}

5. Controller (mvc-controller)

[ApiController]
[Route("api/[controller]")]
public class ProductController : ControllerBase
{
    // GET /api/product
    // GET /api/product/{id}
    // POST /api/product
    // PUT /api/product/{id}
    // DELETE /api/product/{id}
}

🔧 Requirements

Requirement Version
Visual Studio Code ^1.90.0
Target language C# (.cs files only)
.NET SDK 6.0 / 7.0 / 8.0

This extension provides snippets only — no runtime components, no language server, no build tasks.


🤝 Contributing

Pull requests are welcome! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feat/my-snippet)
  3. Add your snippet to snippets/mvc.code-snippets
  4. Update this README's snippet table
  5. Open a Pull Request

📤 Publishing to the VS Code Marketplace

Prerequisites

npm install -g @vscode/vsce

One-time setup

  1. Create a publisher account at marketplace.visualstudio.com
  2. Generate a Personal Access Token (PAT) with Marketplace → Manage scope
  3. Add your publisher name to package.json → "publisher" field

Login

vsce login your-publisher-name
# Paste your PAT when prompted

Package (VSIX only — no publish)

vsce package
# Outputs: aspnet-mvc-snippets-1.0.0.vsix

Publish

vsce publish
# Bumps patch and publishes

Bump version and publish

vsce publish minor   # 1.0.0 → 1.1.0
vsce publish major   # 1.0.0 → 2.0.0
vsce publish patch   # 1.0.0 → 1.0.1

📄 License

MIT © Your Name

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft