أسئلة القسم
تدرب على أسئلة المقابلات في هذا القسم. اكتب إجابتك، قم بتقييمها، أو اضغط على "عرض الإجابة" بعد التفكير.
What’s the difference between ASP.NET MVC and ASP.NET Web Forms? When should you use each? سهل
Aspect | ASP.NET MVC | ASP.NET Web Forms |
---|---|---|
Pattern | Model–View–Controller | Event-driven, Page–Controller |
Separation of Concerns | Strong separation | Tight coupling of UI & logic |
HTML/JS Control | Full control over markup | Uses server controls, ViewState |
Testability | High | Low |
Performance | Lightweight, no ViewState | Heavier due to ViewState |
Learning Curve | Steeper | Easier for WinForms devs |
When to use:
MVC: For modern, testable, SEO-friendly apps requiring fine-grained HTML control. Web Forms: For rapid internal apps where drag-and-drop UI and server controls are desired.
Explain MVC Life cycle سهل
- Routing – URL matched to route.
- Controller Initialization – Controller instance created.
- Action Execution – Action method runs.
- Result Execution – Action returns a result (often a ViewResult).
- View Rendering – Razor engine renders the View to HTML.
What is Rest API? سهل
REST (Representational State Transfer) is an architectural style for building APIs. Uses HTTP verbs to perform CRUD operations on resources (nouns). Stateless: each request contains all info needed. Returns representations like JSON or XML.
Explain the difference between GET, POST, and PATCH in HTTP APIs. سهل
HTTP Verb | Purpose | Idempotent? | Example |
---|---|---|---|
GET | Retrieve data | ✅ Yes | /api/products/1 |
POST | Create new resource | ❌ No | /api/products with body |
PATCH | Partial update of a resource | ❌ No | /api/products/1 with partial JSON |
Difference between MVC and Razor Pages in .NET Core? سهل
Feature | MVC | Razor Pages |
---|---|---|
Structure | Separate Controller + View | Page-centric, code-behind model |
Complexity | Good for large apps | Simpler for small/medium apps |
Routing | Convention + Attributes | Built-in page-based routing |
Testability | High | Also testable but less boilerplate |
What is Scaffolding in MVC? سهل
Automated code generation feature. Quickly creates Controllers, Views, and CRUD actions from a Model. Saves time in prototyping.
What is a Partial View? سهل
A reusable Razor View chunk (like a UserControl). Does not run as a full view; rendered inside another view. Used for headers, footers, sidebars, or shared UI parts.
How do you transfer data from a Controller → View? سهل
- ViewBag (dynamic, short-lived)
- ViewData (dictionary, short-lived)
- TempData (persists across redirect)
- Strongly-Typed Model (best practice)
Example:
public IActionResult Index() {
var model = new ProductViewModel();
return View(model); // strongly-typed
}
What is a DTO (Data Transfer Object)? سهل
A simple object used to transfer data between layers or over the network. No business logic, just properties. Protects your domain models from exposure and reduces payload.
What is the purpose of [NonAction] attribute? سهل
Applied to public methods in a Controller to prevent them from being treated as Actions. Ensures method can be called internally but not via HTTP request.
What is early binding and late binding? سهل
Binding | Meaning | Example |
---|---|---|
Early Binding | Method/member known at compile-time. Faster & type-safe. | Normal C# method call. |
Late Binding | Resolved at runtime. Slower, less type-safe. | Reflection, dynamic keyword. |