7
I’m starting my C# studies with ASP.NET MVC today. I’m still adapting to some things I’m not used to seeing, because I know languages like PHP, Python and Javascript.
I realized that in a code that already came ready, when starting an ASP.NET MVC project with Razor, that some class methods AccountController.cs
, for example, are declared twice.
I did not understand why it is possible to define a method with the same name twice.
As I am used to other languages, I would like an explanation about this.
Example of the code that is in my project:
// GET: /Account/SendCode
[AllowAnonymous]
public async Task<ActionResult> SendCode(string returnUrl, bool rememberMe)
{
var userId = await SignInManager.GetVerifiedUserIdAsync();
if (userId == null)
{
return View("Error");
}
var userFactors = await UserManager.GetValidTwoFactorProvidersAsync(userId);
var factorOptions = userFactors.Select(purpose => new SelectListItem { Text = purpose, Value = purpose }).ToList();
return View(new SendCodeViewModel { Providers = factorOptions, ReturnUrl = returnUrl, RememberMe = rememberMe });
}
//
// POST: /Account/SendCode
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> SendCode(SendCodeViewModel model)
{
if (!ModelState.IsValid)
{
return View();
}
// Generate the token and send it
if (!await SignInManager.SendTwoFactorCodeAsync(model.SelectedProvider))
{
return View("Error");
}
return RedirectToAction("VerifyCode", new { Provider = model.SelectedProvider, ReturnUrl = model.ReturnUrl, RememberMe = model.RememberMe });
}
That is, the declaration of SendCode
is done twice.
What is the meaning of this "duplication" of the name of the methods?
This has something to do with polymorphism or something similar?