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 8129305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:16:04+00:00 2026-06-06T08:16:04+00:00

I’m not quite understanding how this works. Passing parameters from my entity objects works

  • 0

I’m not quite understanding how this works.

Passing parameters from my entity objects works fine. But when I create new fields, only the first one is retrieved.

Model User Class:

public class User {

    [Key]
    public long Uid { get; set; }

    [Required]
    [StringLength(50, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 4)]
    [DataType(DataType.EmailAddress)]
    [Display(Name = "Email:")]
    public string Email { get; set; }

    [Required]
    [StringLength(20, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 4)]
    [Display(Name = "User Name:")]
    public string Username { get; set; }

    public string Password { get; set; }

    public byte Role { get; set; }

    public DateTime Created { get; set; }
}

CSHTML:

@using (Html.BeginForm( null,
                    null,
                    FormMethod.Post,
                    new { id = "regform" })
    ) {
@Html.ValidationSummary(true)
<fieldset>
    <legend>Register</legend>

    <div class="editor-label">
       @Html.LabelFor(model => model.Email)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Email)
        @Html.ValidationMessageFor(model => model.Email)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.Username)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Username)
        @Html.ValidationMessageFor(model => model.Username)
    </div>

    <div class="editor-label">
        Password:
    </div>
    <div class="editor-field">
        @Html.Password("pwd")
    </div>

    <div class="editor-label">
        Confirm Password:
    </div>
    <div class="editor-field">
        @Html.Password("confirm")
    </div>

    <p>
        <input type="submit" value="Register" />
    </p>
</fieldset>
}

Controller:

    [HttpPost]
    public ActionResult Register(User user, string pwd, string confirm) {
        user.Username = confirm;
        user.Created = DateTime.Now;
        user.Role = 255;
        user.Password = EncryptPassword.Password(pwd);


        if (ModelState.IsValid && pwd == confirm) {
            db.Users.Add(user);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        return View(user);
    }

Where I’m getting confused, is pwd picks up fine. confirm on the other hand remains null. My initial thought that it was calling by order and confirm in the model was simply conPwd. When that didn’t work, I changed it’s name to confirm. It still is not working and I can’t find anything that explains how multiple parameters are passed to the controller.

Edit:
Updated my code. Believe it or not, this alone has taken me most of the day to write because I’ve been trying to understand what I’m doing. There is just so much to take in when you’re learning Entities, LINQ, MVC, ASP.NET and Razor all at the same time. Basic C# is the only part I came in to this knowing. 🙂

  • 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-06-06T08:16:04+00:00Added an answer on June 6, 2026 at 8:16 am

    You need a strongly typed view for your RegisterModel then use a Html.BeginForm to post the data to the controller.

    Model

    // This is the Model that you will use to register users
    public class RegisterModel
    {
        [Required]
        [Display(Name = "User name")]
        public string UserName { get; set; }
    
        [Required]
        [DataType(DataType.EmailAddress)]
        [Display(Name = "Email address")]
        public string Email { get; set; }
    
        [Required]
        [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
        [DataType(DataType.Password)]
        [Display(Name = "Password")]
        public string Password { get; set; }
    
        [DataType(DataType.Password)]
        [Display(Name = "Confirm password")]
        [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
        public string ConfirmPassword { get; set; }
    }
    

    View (CSHTML)

    // This is your strongly typed view that will use
    // model binding to bind the properties of RegisterModel
    // to the View.
    @model Trainer.Models.RegisterModel
    
    // You can find these scripts in default projects in Visual Studio, if you are
    // not using VS, then you can still find them online
    <script src="~/Scripts/jquery.validate.min.js"></script>
    <script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
    
    // This is where your form starts
    // The "Account" parameter states what controller to post the form to
    @using (Html.BeginForm((string)ViewBag.FormAction, "Account")) {
        @Html.ValidationSummary(true, "Account creation was unsuccessful. Please correct the errors and try again.")
    
        <fieldset>
            <legend>Registration Form</legend>
            <ol>
                <li>
                    @Html.LabelFor(m => m.UserName)
                    @Html.TextBoxFor(m => m.UserName)
                    @Html.ValidationMessageFor(m => m.UserName)
                </li>
                <li>
                    @Html.LabelFor(m => m.Email)
                    @Html.TextBoxFor(m => m.Email)
                    @Html.ValidationMessageFor(m => m.Email)
                </li>
                <li>
                    @Html.LabelFor(m => m.Password)
                    @Html.PasswordFor(m => m.Password)
                    @Html.ValidationMessageFor(m => m.Password)
                </li>
                <li>
                    @Html.LabelFor(m => m.ConfirmPassword)
                    @Html.PasswordFor(m => m.ConfirmPassword)
                    @Html.ValidationMessageFor(m => m.ConfirmPassword)
                </li>
            </ol>
            <!-- The value property being set to register tells the form
                 what method of the controller to post to -->
            <input type="submit" value="Register" /> 
        </fieldset>
    }
    

    Controller

    // The AccountController has methods that only authorized
    // users should be able to access. However, we can override
    // this with another attribute for methods that anyone
    // can access
    [Authorize]
    public class AccountController : Controller
    {
    
        // This will allow the View to be rendered
        [AllowAnonymous]
        public ActionResult Register()
        {
            return ContextDependentView();
        }
    
            // This is one of the methods that anyone can access
            // Your Html.BeginForm will post to this method and
            // process what you posted.
            [AllowAnonymous]
            [HttpPost]
            public ActionResult Register(RegisterModel model)
            {
                // If all of the information in the model is valid
                if (ModelState.IsValid)
                {
                    // Attempt to register the user
                    MembershipCreateStatus createStatus;
                    Membership.CreateUser(model.UserName, model.Password, model.Email, passwordQuestion: null, passwordAnswer: null, isApproved: true, providerUserKey: null, status: out createStatus);
    
                    // If the out parameter createStatus gives us a successful code
                    // Log the user in
                    if (createStatus == MembershipCreateStatus.Success)
                    {
                        FormsAuthentication.SetAuthCookie(model.UserName, createPersistentCookie: false);
                        return RedirectToAction("Index", "Home");
                    }
                    else // If the out parameter fails
                    {
                        ModelState.AddModelError("", ErrorCodeToString(createStatus));
                    }
                }
    
                // If we got this far, something failed, redisplay form
                return View(model);
            }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.