H
H
helloitsme2014-06-15 11:31:05
Design patterns
helloitsme, 2014-06-15 11:31:05

Autocomplete MVC fields?

There is a model:

public class Works
    {
        public int Id { get; set; }
        public string name { get; set; }
        public string laboriusness { get; set;}
 
        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:dd'/'MM'/'yyyy}", ApplyFormatInEditMode = true)]
        public DateTime completiondate { get; set; }
    }
 
    public class Employyes
    {
        public int Id { get; set;}
        public string nameofemployye { get; set; }     
    }
 
    public class Orders
    {
        public int Id { get; set; }
        
        public int workid { get; set; }
        public int employyeid { get; set; }
        public string laboriusness { get; set; }
        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:dd'/'MM'/'yyyy}", ApplyFormatInEditMode = true)]
        public DateTime startdate { get; set; }
 
        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:dd'/'MM'/'yyyy}", ApplyFormatInEditMode = true)]    
        public DateTime enddate { get; set; }
 
        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:dd'/'MM'/'yyyy}", ApplyFormatInEditMode = true)]
        public DateTime realenddate { get; set; }
    }

I want the workid and employyeid fields from the Orders class to be populated from the ID fields of the works and employyes classes, like how the datapicker works, how can I do that?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
hVostt, 2014-06-15
@hVostt

We need to write an action filter that populates ViewData["employyeid"] with SelectListItem values ​​from the database. Apply the action filter to the action where you want to make a dropdown list with these values. You need to insert @Html.DropDown("employyeid") into the view. The framework will do the rest.
P.S. For workid, the same thing, you can specify the required number of filters for the action.

H
helloitsme, 2014-06-15
@manisha

What does it look like? I don't think so =(

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question