-
Notifications
You must be signed in to change notification settings - Fork 10.1k
MVC Reserved Keywords
Pranav K edited this page Feb 20, 2019
·
3 revisions
There are certain set of keywords ASP.NET Core MVC uses internally, which should be avoided in user-code as it can result in unexpected outcome in certain scenarios.
- The names
controller
,action
,area
, andpage
are reserved keywords used by MVC's routing system. Using these as part of link generations, or as model bound parameters or top level properties will likely bind the reserved route value.
Consider
// /ListProducts/Index.cshtml
@page "{page:int?}"
@functions {
public async Task OnGetAsync(int page)
{
...
}
The parameter page
on the page handler will not be bound correctly since page
is a reserved keyword.
- The following keywords are reserved in the context of a Razor view or a Razor Page:
page
using
namespace
inject
section
inherits
model
addTagHelper
removeTagHelper