ASP.NET Core MVC Guide
Complete overview of Models, Controllers, Views, AJAX calls and request flow used in Sense Softech ERP / POS projects.
| Component | Description |
|---|---|
| Model | Holds data and validation rules. Example: CustomerModel.cs, StockModel.cs |
| Controller | Handles HTTP requests and returns Views or JSON responses. |
| View | Displays data and UI (Razor .cshtml files). |
| GET Action |
[HttpGet]
public IActionResult CustomerEntry()
{
return View(new CustomerModel());
}
|
| POST Action |
[HttpPost] public async Task |
| AJAX Call (jQuery) |
$.ajax({
url: '/Customer/Save',
type: 'POST',
data: $("#frmCustomer").serialize(),
success: function(res) {
if(res.success) swal("Success", res.message, "success");
}
});
|
Typical Controller + Dapper Pattern (Recommended)
public class CustomerController : Controller
{
private readonly ClsSqlHelper _sqlHelper;
public CustomerController(ClsSqlHelper sqlHelper)
{
_sqlHelper = sqlHelper;
}
[HttpPost]
public async Task Save(CustomerModel model)
{
var dp = new DynamicParameters();
dp.Add("@Name", model.Name);
// ... other params
await _sqlHelper.ExecuteNonQueryAsync("sp_SaveCustomer", dp);
return Json(new { success = true });
}
}
MVC Request Flow
1. User opens page → GET Action → Return View
2. User submits form → AJAX POST
3. Controller receives Model
4. ModelState Validation
5. Call ClsSqlHelper (Dapper)
6. Return JSON Response
7. Show SweetAlert / Toast notification
2. User submits form → AJAX POST
3. Controller receives Model
4. ModelState Validation
5. Call ClsSqlHelper (Dapper)
6. Return JSON Response
7. Show SweetAlert / Toast notification
Folder Structure (Recommended)
Controllers
└─ CustomerController.cs
Models
└─ CustomerModel.cs
Views
└─ Customer
└─ CustomerEntry.cshtml
DA (Data Access)
└─ ClsSqlHelper.cs
Best Practice:
Keep Controllers thin. Put all database logic inside ClsSqlHelper or dedicated Repository/Service classes.
Keep Controllers thin. Put all database logic inside ClsSqlHelper or dedicated Repository/Service classes.