How do you add custom validation?
Simple meaning
I implement ValidationAttribute or IValidatableObject for multi-property rules.
Open the full page for Why, Steps, Example and Key takeaway.
Panel-ready ASP.NET MVC questions for freshers and experienced developers. Practice at Coding Cadre in Faridabad, or Online from Delhi NCR.
I implement ValidationAttribute or IValidatableObject for multi-property rules.
Open the full page for Why, Steps, Example and Key takeaway.
A partial is only markup plus a model you already have.
Open the full page for Why, Steps, Example and Key takeaway.
PRG: post-redirect-get so a refresh does not resubmit the form.
Open the full page for Why, Steps, Example and Key takeaway.
Razor encodes @model values by default.
Open the full page for Why, Steps, Example and Key takeaway.
I inject services through the constructor and register them in the container.
Open the full page for Why, Steps, Example and Key takeaway.
Awaiting EF or HTTP calls frees the thread while I/O runs, which helps throughput under load.
Open the full page for Why, Steps, Example and Key takeaway.
Constraints like {id:int} reject non-integers before the action runs.
Open the full page for Why, Steps, Example and Key takeaway.
Response cache headers or in-memory cache for data.
Open the full page for Why, Steps, Example and Key takeaway.
When a type cannot be constructed from simple names, like a comma-separated set of ids or a custom date format.
Open the full page for Why, Steps, Example and Key takeaway.
I catch unhandled exceptions, log with a correlation id, and return a Problem view or JSON.
Open the full page for Why, Steps, Example and Key takeaway.
Authorize Role covers coarse checks.
Open the full page for Why, Steps, Example and Key takeaway.
I cache ViewComponents, avoid N+1 in each widget, and load below-the-fold bits later.
Open the full page for Why, Steps, Example and Key takeaway.
One action does one use case: bind, call a service, map to a view model, return.
Open the full page for Why, Steps, Example and Key takeaway.
I inject fakes for services and assert the ActionResult type and model.
Open the full page for Why, Steps, Example and Key takeaway.
System.Web is gone, HttpContext is different, and many packages were rewritten.
Open the full page for Why, Steps, Example and Key takeaway.
Model holds data and domain rules.
Open the full page for Why, Steps, Example and Key takeaway.
Routes map URL patterns to controller actions.
Open the full page for Why, Steps, Example and Key takeaway.
Razor mixes HTML with C# using @ syntax to generate pages.
Open the full page for Why, Steps, Example and Key takeaway.
Data annotations on the model plus ModelState.IsValid in the action catch bad input.
Open the full page for Why, Steps, Example and Key takeaway.
Filters run before or after actions for cross-cutting concerns like auth, logging, and caching.
Open the full page for Why, Steps, Example and Key takeaway.