I'm new in ASP.net MVC and Razor.

I want to save user birthdate using Drop down list , But I don't know how access selected value in controller . I used TextBoxFor before that it's not appropriate for get date from user . I read a lot of similar question but I didn't understand .

a part of my Register.cshtml :

 <div class="form-group">
        <label class="label">BirthDate</label>
        <div class="col-md-10">
            @Html.TextBoxFor(model => model.UserBirthDate)
            @Html.ValidationMessageFor(model => model.UserBirthDate)            
            <select name="Year">
                <option value="2000">2000</option>
                <option value="2001">2001</option>
                <option value="2002">2002</option>
                <option value="2003">2003</option>
                <option value="2004">2004</option>
                <option value="2005">2005</option>
                <option value="2006">2006</option>
            </select>
            <select name="Month">
                <option value="7">July</option>
                <option value="9">September</option>
                <option value="12">December</option>
            </select>
            <select name="Day">
                <option value="1">1</option>
                <option value="2">2</option>
                <option value="3">3</option>
                <option value="4">4</option>
            </select>
        </div>
    </div>

a part of my Controller :

[HttpPost]
    public ActionResult Register(User user)
    {

        UserRepositories bluser = new UserRepositories();

        if (ModelState.IsValid)
        {
            if(user.UserBirthDate != null)
            {
               /////
            }

            if (bluser.Add(user))
            {

                return MessageBox.Show("Succsess", MessageType.Success);
            }
            else
            {

                return MessageBox.Show(" UNSuccsess", MessageType.Error);
            }
        }
        else
        {


            return MessageBox.Show(ModelState.GetErrors(), MessageType.Warning);
        }

    }

user model :

public partial class User
{
    public int UserID { get; set; }
    public string UserEmail { get; set; }
    public string UserFirstName { get; set; }
    public string UserLastName { get; set; }
    public string UserPassWord { get; set; }
    public string UserCellPhone { get; set; }
    public string UserTell { get; set; }
    public string UserImage { get; set; }
    public string UserAddress { get; set; }
    public Nullable<byte> UserStatus { get; set; }
    public Nullable<System.DateTime> UserBirthDate { get; set; }
    public string UserGender { get; set; }
}

usermetaData.cs

internal class UserMetaData
{
    [ScaffoldColumn(false)]
    [Bindable(false)]
    public int UserID { get; set; }

    public string UserEmail { get; set; }


    public string UserFirstName { get; set; }


    public string UserLastName { get; set; }


    [DataType(DataType.Password)]
    public string UserPassWord { get; set; }

    public string UserCellPhone { get; set; }


    public string UserTell { get; set; }

    public string UserImage { get; set; }
    public string UserAddress { get; set; }


    public Nullable<byte> UserStatus { get; set; }

    public Nullable<System.DateTime> UserBirthDate { get; set; }


    public string UserGender { get; set; }
}
 }
namespace NP1.Models
{
[MetadataType(typeof(NP1.Models.MetaData.UserMetaData))]
public partial class User
{

    public string UserConfirmPassWord { get; set; }

    public string Year { get; set; }
    public string Month { get; set; }
    public string Day { get; set; }
}

Related posts

Recent Viewed