I am trying to create a simple reporting page with a static number of dropdown lists containing the names of the available reports and add them to the collection of reports for the generation of the comparison report.
Here is my ViewModel
public class DealSummaryComparisonViewModel
{
public ICollection<DealSummary> AvailableDealSummaries { get; set; }
public ICollection<int> SelectedDealSummaries { get; set; }
}
and here is my View
@model FRSDashboard.Web.Models.DealSummaryComparisonViewModel
@{
ViewBag.Title = "FRS Dashboard :: Deal Summary Comparison Report";
var dealSummaryList = new SelectList(Model.AvailableDealSummaries,
"DealSummaryId", "FileName");
}
<h2>Deal Summary Comparison Report</h2>
<p>Please select at least two files to compare:</p>
@using (Html.BeginForm("DealSummaryComparison", "Reporting", FormMethod.Post)) {
for (int i = 0; i <= 4; i++) {
<div>File @i+1: @Html.DropDownListFor(m => m.SelectedDealSummaries,
dealSummaryList)</div>
}
<div><input type="submit" name="download" id="download" value="Download To Excel" /></div>
}
This works for populating the dropdown lists but I'm not sure how to populate the SelectedDealSummaries collection or remove a selected deal summary from the list (similar to what I would do with WebForms).
Also, how would I add an item to the list like "Select Deal Summary..."?
UPDATE:
I have modified my code to use indexing and call a javascript function.. but am stuck on what to do in javascript.
@using (Html.BeginForm("DealSummaryComparison", "Reporting", FormMethod.Post)) {
for (int i = 0; i <= 4; i++) {
<div>
File @(i + 1):
@Html.DropDownListFor(m => m.SelectedDealSummaries[i], dealSummaryList,
new {onchange = "updateAvailable()"})
</div>
}
}
<script type="text/javascript">
function updateAvailable() {
alert("updating");
}
</script>