none
Are those two Methods Overload methods RRS feed

  • Question

  • Hi, I'm working on C# ASP.Net MVC for a few month now, and just want to know if these two below Register methods locaed in the Default Microsoft Template Controller are OOP overload concept.

    Also, is there any override method in the Default ASP.Net MVC template ???

    //
            // GET: /Account/Register
            [AllowAnonymous]
            public ActionResult Register()
            {
    
                GeneratePassword();
    
                return View();
            }
    
            
    
            //
            // POST: /Account/Register
            [HttpPost]
            [AllowAnonymous]
            [ValidateAntiForgeryToken]
            public async Task<ActionResult> Register(RegisterViewModel model)
            {
                if (ModelState.IsValid)
                {
                    
                    ... 
    
                    if (result.Succeeded)
                    {
                        
                        if (userTbl >= 1)
                        {
    
                            //record found in table
                            //Keep loading Login Page
    
                            // Add user to selected Role
                            UserManager.AddToRole(user.Id, roleAccountType);
                            
                            return RedirectToAction("Index", "ManageAccounts");
    
                        }
                        else
                        {
                            
                            // Table User is empty.
                            // No record found in table 'User'
                            // User must register first before using the Web App.
    
                            
    
                            return RedirectToAction("Index", "Home");
    
                         }
    
                    }
                    
                    else
                    {
                        AddErrors(result);
                    }
    
            }
    
                // If we got this far, something failed, redisplay form
                return View(model);
    
           }



    • Edited by Christine25 Thursday, August 15, 2019 10:36 AM
    • Moved by CoolDadTx Friday, August 16, 2019 3:29 PM ASP.NET related
    Thursday, August 15, 2019 10:35 AM

Answers

  • Yes you are right, it is method overloading and you can override methods too if you want to as there are methods in the Controller class from which each controller inherits, those can be overridden in your own controller class if you want to.

    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered "Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]


    Blog | LinkedIn | Stack Overflow | Facebook
    profile for Ehsan Sajjad on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by Christine25 Friday, August 16, 2019 4:33 PM
    Thursday, August 15, 2019 1:27 PM

All replies

  • Yes you are right, it is method overloading and you can override methods too if you want to as there are methods in the Controller class from which each controller inherits, those can be overridden in your own controller class if you want to.

    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered "Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]


    Blog | LinkedIn | Stack Overflow | Facebook
    profile for Ehsan Sajjad on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by Christine25 Friday, August 16, 2019 4:33 PM
    Thursday, August 15, 2019 1:27 PM
  • Thanks. How would I override it please?

    Can you please show me an example from the above template?

    Friday, August 16, 2019 1:44 PM
  • Yes this is standard function overloading. No it doesn't work the way you might apply it the OOP world. The way MVC routing works doesn't play into "overloading" like a regular method call would. All the routing is based upon routing rules and information that is external to the function itself (aka URL, verbs, etc). MVC routing will not distinguish 2 "overloads" based upon parameters like a method call would.

    Please post your question in the ASP.NET forums.


    Michael Taylor http://www.michaeltaylorp3.net

    Friday, August 16, 2019 3:29 PM