we are about to develop an ERP application e commerce so we structed b/w choosing mvc and web api
we have to build it in core now so give me some suggestion which is better and also in for future which can be sustain long time according latest tech trndz..
Loading

Jignesh KumarRank #91 · 22.9K reputationPosted Jan 16, 2025, 12:12 AM EST
Hello Jaya prakas,
Based on my understanding of the latest trends, you can consider the following technologies: Web API combined with a Single Page Application (SPA).
Sangeetha SRank #212 · 11.4K reputationPosted Jan 16, 2025, 12:15 AM EST
Choosing between MVC (Model-View-Controller) and Web API (Application Programming Interface) for building an e-commerce website depends on your specific needs:
MVC:- Best for: Traditional web applications where you need server-side rendering of HTML.
- Pros:
- Provides a complete framework for building web applications.
- Good for SEO since it generates HTML on the server.
- Easier for developers who want to work with a full-stack solution.
- Cons:
- Less flexibility for building single-page applications (SPAs).
- Can be heavier on server resources since it renders pages on the server.
Web API:Conclusion:
If your e-commerce site will mainly serve web users and you want to manage everything in one place, MVC might be the better choice.
Tuhin PaulRank #7 · 71.9K reputationPosted Jan 16, 2025, 12:12 PM EST
API Controller for Products
using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; namespace ECommerceERP.Controllers { [Route("api/[controller]")] [ApiController] public class ProductsController : ControllerBase { private static List products = new List { new Product { Id = 1, Name = "Laptop", Price = 999.99 }, new Product { Id = 2, Name = "Smartphone", Price = 499.99 }, new Product { Id = 3, Name = "Headphones", Price = 199.99 } }; // GET: api/products [HttpGet] public ActionResult> GetProducts() { return Ok(products); } // GET: api/products/{id} [HttpGet("{id}")] public ActionResult GetProduct(int id) { var product = products.Find(p => p.Id == id); if (product == null) { return NotFound(); } return Ok(product); } } public class Product { public int Id { get; set; } public string Name { get; set; } public double Price { get; set; } } }React Component (ProductList.js):
import React, { useEffect, useState } from 'react'; const ProductList = () => { const [products, setProducts] = useState([]); useEffect(() => { fetch("http://localhost:5000/api/products") .then((response) => response.json()) .then((data) => setProducts(data)) .catch((error) => console.error('Error:', error)); }, []); return ( Products {products.map((product) => ( {product.name} - ${product.price} ))} ); }; export default ProductList;If you decide to go with MVC, it would make more sense when your application needs to serve HTML views to users directly, where you control the UI layout using Razor views. If you're looking for flexibility, performance, and easier maintenance, Web API is preferred.
MVC would still be a viable choice if:
Tuhin PaulRank #7 · 71.9K reputationPosted Jan 16, 2025, 12:14 PM EST
For an e-commerce ERP application, the Web API approach is generally the better choice, particularly for long-term sustainability and scalability. You can combine it with modern front-end technologies (React, Angular, Vue.js) and easily expose your services to other systems or mobile applications.
Configuring CORS
Since your React front-end and Web API might run on different ports during development, you'll need to configure CORS (Cross-Origin Resource Sharing) in the Web API.
In
Startup.cs(ASP.NET Core 5 or 6):public void ConfigureServices(IServiceCollection services) { services.AddCors(options => { options.AddPolicy("AllowAllOrigins", builder => builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader()); }); services.AddControllers(); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseCors("AllowAllOrigins"); app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }