I'm starting my studies in C # with ASP.NET MVC today. I'm still adapting with some things I'm not used to seeing, because I know languages like PHP, Python and JavaScript.
I noticed that in a code that has already come ready, when starting an ASP.NET MVC project with Razor, that some methods of class AccountController.cs
, for example, are declared twice.
I do not understand why it is possible to define a method with the same name twice.
As I'm used to other languages, I'd like an explanation on this.
Sample 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 method names?
Does this have anything to do with polymorphism or something similar?