Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6813533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:34:53+00:00 2026-05-26T20:34:53+00:00

Take this snippet out of a controller, for example: public ActionResult Login() { if

  • 0

Take this snippet out of a controller, for example:

public ActionResult Login()
{
    if (User.Identity.IsAuthenticated)
    {
        return RedirectToAction("Index", "Home");
    }
    else
    {
        return View();
    }
}

//
// POST: /User/Login

[HttpPost]
public ActionResult Login(LoginModel lm, string returnUrl)
{
    if (ModelState.IsValid)
    {
        if (Membership.ValidateUser(lm.UserName, lm.Password))
        {
            FormsAuthentication.SetAuthCookie(lm.UserName, lm.RememberMe);
            if (Url.IsLocalUrl(returnUrl) &&
                returnUrl.Length > 0 &&
                returnUrl.StartsWith("/") &&
                !returnUrl.StartsWith("//") &&
                !returnUrl.StartsWith("/\\"))
            {
                return Redirect(returnUrl);
            }
            else
            {
                return RedirectToAction("Index", "Home");
            }
        }
        else
        {
            ModelState.AddModelError("", "Username and Password combination is incorrect");
        }
    }

    return View();
}

My question is, with the overloaded method of Login() (for the HTTP POST), what calls this method with the first parameter as a LoginModel class, and the second parameter as a string? My Login.cshtml view uses a submit button, so I am curious as to how these parameters get passed to the Login() method? What’s to stop me from adding a third parameter? And how would that parameter get passed??

I know this is a basic question, I’m just trying to understanding the connecting piece between Views and Controllers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:34:54+00:00Added an answer on May 26, 2026 at 8:34 pm

    This process is called Model Binding, lots of resources on it…I would start with How to implement a custom one because from that you will then understand how and why the process works.

    http://buildstarted.com/2010/09/12/custom-model-binders-in-mvc-3-with-imodelbinder/
    http://bradwilson.typepad.com/blog/2010/10/service-location-pt9-model-binders.html

    EDIT:

    There is a default model binder which exists which takes items in the post collection like form data and url parameters and tries to match them up with items which you have told the controller to expect. It works something like this…

    Request comes in,
    MVC decides which controller should get the request
    MVC then looks at the HTTP Method, was it a GET or POST?
    If it was a post then it looks for the controller action with the HttpPost attribute
    MVC then looks at the parameters you have defined…

    In your case it says I have a LoginModel and a returnUrl;
    MVC now is happy – it knows where things are going so now it looks at what you sent…
    It looks at your post data (the form fields and query string parameters)
    One by one it looks at their names and then tries to find a match in your controller parameters.

    It finds a Username field in the form data, it takes a look at your parameters and asks if there is a Username? No, well maybe Username is a property of LoginModel…it then looks through LoginModel. Aha it says, found one. MVC then creates an instance of LoginModel and sets the Username property to the value you posted.

    This process continues for each of the things it finds in your form and query string. There are a bunch of rules it follows but you get the picture – this matching is part of the ‘convention over configuration’ beauty of MVC.

    This whole process above it model binding and since MVC implements this default behavior you do not see it written out in the Global.asax or anything, it is just part of MVC.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Take this code snippet for example: window.location.href = 'mysite.htm#images'; Already being on the site
Take this sample class as an example: [AttributeUsage(AttributeTargets.All, AllowMultiple=true)] public class BugFixAttribute : System.Attribute
Take this class as example: public class Category : PersistentObject<int> { public virtual string
Take this code snippet as example: union stack { int a; float b; };
Take this non-compiling code for instance: public string GetPath(string basefolder, string[] extraFolders) { string
Take this example code (ignore it being horribly inefficient for the moment) let listToString
Take this method /** * @return List of group IDs the person belongs to
take this simple code: class A{ public: virtual void foo() = 0; void x(){
First of all, please help me out! I can not take this anymore. I
I'm having trouble figuring out a clean way to do this. Let's take for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.