c# - MVC 4 DropDownList can't add to model -
Hi, I'm new to MVC 4 and went into an error while using Html.DropDownList.
This is my current code.
Model for jobs:
Namespace payroll.CORE {Public class jobs {Public Entove Job ID; Set; } Public String JobTitle {get; Set; } Public virtual iconging & lt; Employee & gt; Employee {receive; Set; }}} Model for Employee:
Public Ent Amplifier {get; Set; } Public string name {get; Set; } Public string aliases {get; Set; } Receive public int phone number { Set; } Receive public et al. Set; } Public String Address1 {get; Set; } Public string address 2 {get; Set; } Public String City {Received; Set; } Public int postcode {get; Set; } Receive public string {name}; Set; } Public Int Bank Account Number {Received; Set; } Get the public string peinterval { Set; } Public Double Normal Rate {get; Set; } Public Double Overtime Rate {get; Set; } {Get Public Double Sethors; Set; } Public System DateTime Date Offoffing {Received; Set; } Public Systems Datetime Last Payment Received (Receive; Set;} Public String Active {get; set;} Public Ent Ubid {Received; Set;} Public Virtual Ilkening & lt; Absent & gt; Absents {Receive; Set;} Public Virtual IconKing & Bonus; Bonus & gt; Bonus {Received; Set;} Public Virtual Job Job {Get; Set;} Public Virtual Icons & lt; Vacation & gt; Holidays {Receive; Set;} Public Virtual iconinking & lt; hours work & gt; hours workings {get; set;} public virtual icon list; payrolls; payroll {receive; set;} public virtual icons & lt; deduction & gt; deduction {Receive; Set;} See:
@ Html.LabelFor (model) = & Gt; model.JobID) Controller:
[HTPGet] Create Public ActionCarts () {Sue Chi & amp; lt; SelectListItem & gt; Jobs = New list & lt; SelectListItem & gt; (); & Lt; Jobs & gt; List = bll.GetJobCatergories (); Forchach (all in the list) {jobs.Add (new selection listEstam {text = A.job title, value = AZOBid.ToString ()}); } ViewBag.ListSL = Jobs; See Return (); } Now I have no way to get the value of job ID in my model. I have HTML. Have tried to use for the DRODOWN LIST, but have not received it to populate it with select ITMs.
I have no problem in working with hidden areas or anything, so any help would be greatly appreciated.
Thanks in advance
EDIT: Sorry should have been a bit more clear. I am building an employee and the employee is assigned a job. Therefore, I am trying to add the value of the selected item list value to the employee in the Ent Aubid.
In addition, this price is showing in the dropdown list, I need to add the selected model to the employee model at the time of submission.
OK, try the model now,
@ html .DropDownListFor (mdl = & gt; mdl.Job.JobID, New SelectList (ViewBag.ListSL, "Value", "Text", Model.JobID), "- Please Select -") < P> I will also add, personally, I do not like the use of ViewBag, because you lose steady typing and that's why this artist is back in the SelectList case. Whenever I need a drop down list, I have a fixed asset on the model that will populate the drop down list, return all the items, so I end up in the end, for example: New SelectList (Model AllJobs, ....)
Comments
Post a Comment