0

Can someone kindly let me know how can we pass on a argument from the view to controller, which loads the model.

In the below model, TaskNames gets loaded in a multi select box and MonthEnd gets loaded in a drop down box.

Model

public class TaskAssignModel
{
    public List<string> TaskNames { get; set; }
    public List<Task> Tasks { get; set; }
    public List<MonthEndObj> MonthEnd;
}

Whenever i change the MonthEnd dropdown box ,Tasknames should be loaded based on the value selected in the MonthEnd dropdown.

How is this achievable ? Would like to know if there is a way to get this done through ajax.

***Controller****

  public ActionResult AssignMonthEnd()
    {
        TaskAssignModel tm = new TaskAssignModel();
        DataAccess DA = new DataAccess();

        tm.Tasks = new List<Task>();
        tm.Tasks = DA.getTasks();
        tm.MonthEnd = DA.getActiveMonthEnd();
        return View(tm);
    }

View

  @Html.ListBoxFor(m => m.TaskNames, new MultiSelectList(@Model.Tasks, "TaskID", "TaskName", @Model.TaskNames), new { style = "height:200px; width:400px;overflow-x: scroll", size="5"})
  @Html.DropDownListFor(m => m.MonthEnd, new SelectList(Model.MonthEnd,"ActiveMonthEnd","ActiveMonthEnd",0)) 
user3173346
  • 85
  • 2
  • 12
  • 1
    Possible duplicate of [Populate DropDownList using AJAX MVC 4](http://stackoverflow.com/questions/30084568/populate-dropdownlist-using-ajax-mvc-4) – ADreNaLiNe-DJ Apr 05 '16 at 11:15
  • You need to handle the change event of the dropdownlist and use ajax to call a server method that returns the data to create the options for the listbox. Refer [this answer](http://stackoverflow.com/questions/28627421/better-way-to-load-2-dropdown-in-mvc/28640420#28640420) for an example –  Apr 05 '16 at 11:16

0 Answers0