ASP — ASP.NET MVC
MVC Pattern
- Model: Data and business logic
- View: User interface
- Controller: Handles requests
Controller
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult About()
{
ViewBag.Message = "About page";
return View();
}
}
View
@{
ViewBag.Title = "Home";
}
<h1>Welcome to ASP.NET MVC</h1>
<p>@ViewBag.Message</p>
Model
public class User
{
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
}
Razor Syntax
@model MyApp.Models.User
<h1>@Model.Name</h1>
@if (Model.IsActive)
{
<span>Active</span>
}
@foreach (var item in Model.Items)
{
<li>@item.Name</li>
}
Mini Practice
- Create a controller
- Create a view
- Pass data with ViewBag
- Use Razor syntax
Up Next
Continue with ASP.NET Web Forms — Web Forms.
Related Topics
Frequently Asked Questions about ASP.NET MVC
What is ASP.NET MVC in ASP?
ASP.NET MVC is a fundamental concept in ASP. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn ASP.NET MVC?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn ASP.NET MVC.
Why is ASP.NET MVC important in ASP?
ASP.NET MVC is essential for ASP development. Understanding this concept will help you write better code and solve real-world problems more effectively.