Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have two dropdown at layout screen which are shared in two views.
1. Scheduler view 2. worklistview

I have to populate both dropdown on Page load also on selection of first dropdown other dropdown value should populate.

Scheduleview screen and worklist screen should change based on dropdown vaue.
I have created scheduleviewmodel which is binding to these two dropdowns at layout page.
ScheduleviewModel is binding to scheduler screen but worklistviewModel binding to worklist screen.

So when I am moving to worklist screen dropdown at layout throwing exception.As this view using worklistViewModel.

Please help me how can I move this to common model.

worklistview searching for scheduleviewmodel as layout using it but worklistview using worklistViewModel.

How to use separate model for layout which can be used by both views.


Thank You.

What I have tried:

I have javascript written to populate dependent dropdown and load Schedule screen.
Layout page :
C#
@model  ORSA.ViewModel.ScheduleViewModel
    @Html.DropDownListFor(m => m.CurrentFacilityId, new SelectList(Model.FacilityList, "FacilityId", "FacilityName"), new {@class = "dropdown1"})
    
    @Html.DropDownListFor(m => m.CurrentLocationId, new SelectList(Model.LocationList, "LocationId", "LocationName"), "All Locations", new { @class = "dropdown1" })


ScheduleController :
C#
public ActionResult Schedule() 
    {
      private ScheduleViewModel model = new ScheduleViewModel();
    //to populate dropdown at page load 
     model.FacilityList = helpObj.GetFacilityList(); //first dropdown list
     model.LocationList = helpObj.GetLocations(facilityId); //dependent dropdown
     return view(model)
    }


C#
//Schedule.cshtml 
@model ORSA.ViewModel.ScheduleViewModel
//code written here


C#
//worklist.cshtml
@model ORSA.ViewModel.WorklistViewModel
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900