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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:19:47+00:00 2026-05-24T17:19:47+00:00

Here’s what I have so far Model and View: public class RegisterModel { [Required]

  • 0

Here’s what I have so far Model and View:

public class RegisterModel
{
    [Required]
    [Display(Name = "Usuario")]
    public string UserName { get; set; }

    [Required]
    [DataType(DataType.EmailAddress)]
    [Display(Name = "Correo")]
    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 = "Contraseña")]
    public string Password { get; set; }

    [DataType(DataType.Password)]
    [Display(Name = "Confirme Su Contraseña")]
    [Compare("Password", ErrorMessage = "Sus contraseñas no son las mismas.")]
    public string ConfirmPassword { get; set; }

    [Required]
    [Display(Name = "Direccion")]
    public string Address { get; set; }

    [Required]
    [Display(Name = "Telefono Fijo")]
    public string Telephone { get; set; }

    [Required]
    [Display(Name = "Celular")]
    public string MobilePhone { get; set; }

    [Required]
    [Display(Name = "Fecha de Nacimiento")]
    public DateTime DateOfBirth { get; set; }

    [Required]
    [Display(Name = "Sexo")]
    public bool Sex { get; set; }

    [Required]
    [Display(Name = "Pais")]
    public int Country { get; set; }
}

@model Foo.WebUI.Models.RegisterModel

@{
    ViewBag.Title = "Register";
}

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

<div id="registerform">
    <h2>Cree Su Cuenta</h2>

    @using (Html.BeginForm())
    {
        @Html.ValidationSummary(true)        

            <h3>Informacion de Usuario</h3>
            <div class="editor-field">
                @Html.LabelFor(model => model.UserName)
                @Html.EditorFor(model => model.UserName)
                @Html.ValidationMessageFor(model => model.UserName)
            </div>

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

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

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

            <h3>Informacion Personal</h3>

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

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

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

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

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

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

            <p>
                <input type="submit" value="Create" />
            </p>
    }
</div>

Now, since my User will belong to a single country, in the database it has a foreign key reference to the Country table. In my model, I set the Country property to be of type int. Is this correct?

How would I correctly set this up so a dropdownlist is shown for choosing a country in the View but a numerical value is saved for persistance to the database?

  • 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-24T17:19:47+00:00Added an answer on May 24, 2026 at 5:19 pm

    Your CountryId can remain an int (or any type you use for your ids). The Select List can be initialized with the appropriate value field for the selection, and the type will match without the need for conversion.

    Your model will have to be part of a viewmodel that provides to the view what is needed to make the drop down list working (mostly a SelectList ).

    public class RegisterViewModel
    {
      public RegisterModel register { get; set; }
    
      public SelectList SelectCountriesList { get; set; }
    }
    

    The initilisation of this ViewModel will depend on how you work in your controller.

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

Sidebar

Related Questions

Here is what I am trying to achieve in PHP: I have this string:
Here's a problem I ran into recently. I have attributes strings of the form
Here is the issue I am having: I have a large query that needs
Here's my scenario - I have an SSIS job that depends on another prior
Here we go again, the old argument still arises... Would we better have a
Here is what I have: Dim cmsManager As New Telerik.Cms.CmsManager() Dim currentNode As Telerik.Cms.Web.CmsSiteMapNode
Here's a strange question for you guys, I have a nice sorted list that
Here's the basic setup: I have a thin bar at the top of a
Here is my problem : I have a post controller with the action create.
Here is the problem I'm trying to solve for my game. I have this

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.