Bind the location from the View and access here as below. If you are unsure how to bind from View, please provide your view code.
public void addUser(User_Details_Class UDCObj)
{
// Creating Object to Store data and assingning Data
WM_DB.User_Details UDObj = new User_Details();
// Assinging
UDObj.UId = UDCObj.UId;
UDObj.UName = UDCObj.UName;
UDObj.UPassword = UDCObj.UPassword;
UDObj.ULocation = UDCObj.Location; // My code, but will only be available if you bind it from View.
// Here it is clear that i am assigning values one by one like id,password and
// here i am failed to read the value form dropdown.
// If we catch then surely we can add it into user table by combing my code and your code...
// I hope u understand my code
//Saving Data
dbcontext.User_Details.AddObject(UDObj);
dbcontext.SaveChanges();
}
Don't forget to "Mark As Answer" if a post helps you.
In my variable declarion is as follows for "User" registration viewModel class
see this once line
public virtual IEnumerable<Organization_Details_Class> Organization_Details_Class { get; set; }
is it correct or not?
public class User_Details_Class
{
public WM_DBEntities dbcontext = new WM_DBEntities();
[Key]
public int OId { get; set; }
[Key]
public int UIndex{get;set;}
[Required(ErrorMessage = "Enter User Login ID")]
[Display(Name = "User Login ID")]
public string UId{get; set;}
[Required(ErrorMessage = "Enter User Full Name")]
[Display(Name = "User Full Name")]
public string UName{get;set;}
[Required(ErrorMessage = "Enter Password")]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string UPassword{get; set;}
[Required(ErrorMessage = "Please Confirm Password")]
[DataType(DataType.Password)]
[Display(Name = "Confirm Password")]
[Compare("UPassword", ErrorMessage = "The password and confirmation password did not match.")]
public string UConfirmPassword { get; set; }
public virtual LogIn_Class LogIn_Class { get; set; }
public virtual IEnumerable<Organization_Details_Class> Organization_Details_Class { get; set; }
pavankumarmc...
Member
7 Points
97 Posts
Re: Read The Data From DropDown in ASP.Net MVC3
May 12, 2012 08:59 AM|LINK
Hi,
It is very clear and simple that i am not getting any kind of error with the code which is wrote above....
I am able to add the user successfully with id, password and etc but
In addition to that, i want to add the Location Name too to database which is selected from dropdown list...
I mean please write your code here
UDObj.OLocation = Here Your code to get the data from dropdown list, so that i will store in db...
I hope u understand clearly now...
pavankumarmc...
Member
7 Points
97 Posts
Re: Read The Data From DropDown in ASP.Net MVC3
May 12, 2012 09:01 AM|LINK
If i am storing without Location,
then,
it is storing null value in DB.
now i want India,England etc here
pavankumarmc...
Member
7 Points
97 Posts
Re: Read The Data From DropDown in ASP.Net MVC3
May 12, 2012 09:16 AM|LINK
Hi
It is simple and clear that,
see once here,
Obj.OLocation = // code to get the data from the dropdown list
so that we can store this to db with help of above previous cod...
I hope u understand it
If we the
abdu292
Participant
1553 Points
371 Posts
Re: Read The Data From DropDown in ASP.Net MVC3
May 12, 2012 09:34 AM|LINK
Bind the location from the View and access here as below. If you are unsure how to bind from View, please provide your view code.
public void addUser(User_Details_Class UDCObj) { // Creating Object to Store data and assingning Data WM_DB.User_Details UDObj = new User_Details(); // Assinging UDObj.UId = UDCObj.UId; UDObj.UName = UDCObj.UName; UDObj.UPassword = UDCObj.UPassword; UDObj.ULocation = UDCObj.Location; // My code, but will only be available if you bind it from View.With best regards,
pavankumarmc...
Member
7 Points
97 Posts
Re: Read The Data From DropDown in ASP.Net MVC3
May 12, 2012 10:04 AM|LINK
Sure,
I dont know how to bind from View
Please see here once the ViewCode
@model EMVC_CSS.Models.ModelClasses.User_Details_Class @{ ViewBag.Title = "Index"; } <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> @using (Html.BeginForm()) { @Html.ValidationSummary(true) <div class="center_div"> <center><div class="myfont4">User SignUp Form</div></center> <br /> <center><div class="myfont">@Html.LabelFor(model => model.UId)</div></center> <center> @Html.EditorFor(model => model.UId)<br /><div class="myfont3">@Html.ValidationMessageFor(model => model.UId)</div></center> <br /> <center><div class="myfont">@Html.LabelFor(model => model.UName)</div></center> <center> @Html.EditorFor(model => model.UName)<br /><div class="myfont3">@Html.ValidationMessageFor(model => model.UName)</div></center> <br /> <center><div class="myfont">@Html.LabelFor(model => model.UPassword)</div></center> <center> @Html.EditorFor(model => model.UPassword)<br /><div class="myfont3">@Html.ValidationMessageFor(model => model.UPassword)</div></center> <br /> <center><div class="myfont">@Html.LabelFor(model => model.UConfirmPassword)</div></center> <center> @Html.EditorFor(model => model.UConfirmPassword) <br /><div class="myfont3">@Html.ValidationMessageFor(model => model.UConfirmPassword)</div></center> @Html.DropDownList("OLocation") // I think you will bind here..... <center><p><input type="submit" value="Create" /> <input type="reset" value="Clear" /> <font face="verdana" color="black"size="3">@Html.ActionLink("Go Home", "Index", "Home")</font></p></center> </div> }pavankumarmc...
Member
7 Points
97 Posts
Re: Read The Data From DropDown in ASP.Net MVC3
May 12, 2012 10:08 AM|LINK
I am doing this application using
Database First Approach but not with Code First Approach...
Please remind this
abdu292
Participant
1553 Points
371 Posts
Re: Read The Data From DropDown in ASP.Net MVC3
May 12, 2012 10:10 AM|LINK
Bind same as other controlls. Why you omit only this field from binding? I.e;
Is there any specific reason for that?
With best regards,
pavankumarmc...
Member
7 Points
97 Posts
Re: Read The Data From DropDown in ASP.Net MVC3
May 12, 2012 10:13 AM|LINK
I will check once update u if working or not...
Wait once now...
pavankumarmc...
Member
7 Points
97 Posts
Re: Read The Data From DropDown in ASP.Net MVC3
May 12, 2012 10:21 AM|LINK
Hi it is showing error
and saying that..
cannot conver lambda expression to type 'string' because it is not a delegate type
pavankumarmc...
Member
7 Points
97 Posts
Re: Read The Data From DropDown in ASP.Net MVC3
May 12, 2012 10:24 AM|LINK
In my variable declarion is as follows for "User" registration viewModel class
see this once line
public virtual IEnumerable<Organization_Details_Class> Organization_Details_Class { get; set; }
is it correct or not?
public class User_Details_Class { public WM_DBEntities dbcontext = new WM_DBEntities(); [Key] public int OId { get; set; } [Key] public int UIndex{get;set;} [Required(ErrorMessage = "Enter User Login ID")] [Display(Name = "User Login ID")] public string UId{get; set;} [Required(ErrorMessage = "Enter User Full Name")] [Display(Name = "User Full Name")] public string UName{get;set;} [Required(ErrorMessage = "Enter Password")] [DataType(DataType.Password)] [Display(Name = "Password")] public string UPassword{get; set;} [Required(ErrorMessage = "Please Confirm Password")] [DataType(DataType.Password)] [Display(Name = "Confirm Password")] [Compare("UPassword", ErrorMessage = "The password and confirmation password did not match.")] public string UConfirmPassword { get; set; } public virtual LogIn_Class LogIn_Class { get; set; } public virtual IEnumerable<Organization_Details_Class> Organization_Details_Class { get; set; }