Mid
From PDF
MVC
ASP.NET Core MVC
Explain the MVC pattern.
Short answer: MVC stands for Model–View–Controller, a design pattern that separates application logic into three layers: Model – Represents the data and business logic (e.g., Product, Customer, Order). View – The UI or presentation layer that displays data (Razor views). {
Example code
public IActionResult Details(int id)
{
var product = _service.GetById(id);
return View(product);
}
} Notes: Action methods cannot be private or static. They respond to routes like /Product/Details/5. 🎯 6. What are Action Results? An Action Result represents the response returned to the client — view, JSON, redirect, file, etc. SP.NET Core provides many result types: ViewResult JsonResult RedirectResult FileResult ContentResult StatusCodeResult 🔍 7. Difference between ViewResult, JsonResult, and ContentResult. Type Used For Example ViewResult Returns an HTML view return View("Details", model); JsonResult Returns JSON data return Json(model); ContentResul Returns plain text or custom content return Content("Hello World"); IActionResult is an interface that represents the result of an action method. It allows flexibility — you can return any kind of result (view, JSON, redirect, etc.) from the same method. Example: public IActionResult Index()
{
if (!User.Identity.IsAuthenticated)
return RedirectToAction("Login");
return View();
} 🧠 9. How does model binding work? Model binding automatically maps data from the HTTP request (query string, route, body, form) to method parameters or model objects. Example: public IActionResult Save(Product model)
{ // model properties are automatically filled _service.Add(model); return RedirectToAction("Index");
}
{ [Required] public string Name { get; set; } [Range(1, 10000)] public decimal Price { get; set; }
} In a controller: if (!ModelState.IsValid)
return View(model);
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png