I'm new to MVC. I can not understand how one can bind property, For example,:
public class jobs {public string name {get; Set; }} Public class carpenter: Job {} Public class unemployed: Job {} Public class Painter: Job {} Public class person {public person} {this.Job = new unemployed (); } Public Job Job (Received; Set;}} That is; A person gets some type of job. Now I have to show a scene where the user can choose a job for a person I want to use radiobuttons to display all the avalable work types I should also like that the existing job type should be selected as the default, and of course I would like to The person has the job type update on the postback. I am trying to use the razor how do you do it?
I will have a string model property an identifier for the job type: public class EmployeeViewModel {public string JobType {get; set; }} Then you can create a bunch of radibutions in your scene, where prices are all available. Use a factory category:
Public stable class jobfactory {public job GetJob (string id) {switch} (id) {case "CA": return new carrier (); ...}}} Then you can call it in your controller:
public action MyAction (employee view model_m) {var person = New person (); Person.Job = JobFactory.GetJob (m.JobType); ...} You can benefit from switching the string id for anonym and using RadioButtonListFor in your view here is an answer Which shows:
Hope it helps.
No comments:
Post a Comment