javascriptc#asp.net-mvc-5dropdownselectionchanged

Load column on drop down change selection in mvc JavaScript


How to bring the employee name list in one column on selection of project name drop-down list? At the same time while besides employee name 1 textbox and one date filterbox also should generate dynamically. I'm am not good in scripting technologies need some guidance.


Solution

  • Here's how I would do it, if anyone has any criticisms please let me know!

    1. In your controller action for the page return a list of Project objects in a View Model. Each Project object should have at least two properties; one for the name and one for a unique ID. In the Razor view for the page, render the Project objects via a the DropDownList HTML Helper.

    2. Next, set up a Web API endpoint for retrieving a list of Employee's based on the Project they are assigned to.

    3. In your Razor page which displays the lists, write some JavaScript which executes on change of the value of the Project DropDownList. The JavaScript should take the updated value of the Project dropdown, use this value to call the Web API endpoint for retrieving Employee's (based on Project ID), and render the resulting data in a HTML select element.