Hi I have the following foreach that creates rows in a table.
_Summary.cshtml
@model KpiSummaryViewModel
...
@foreach (TimeIntervalAndStatus error in Model.MergedErrorTimeIntervals)
{
<tr>
<td style="font-size: small" class="td downTimes">@error.TimeStart</td>
<td style="font-size: small" class="td downTimes">@error.TimeEnd</td>
<td style="font-size: small" class="td downTimes">@(error.TimeEnd -
error.TimeStart)</td>
<td style="font-size: small" class="td downTimes">
@Html.ActionLink("Details", "Index", "Details", error, null)
</td>
</tr>
}
When I click the ActionLink above, I want to pass error but also KpiSummaryViewModel.SummaryInformation.Name to the Details Controller.
My DetailsController
public class DetailsController : Controller
{
private TimeIntervalAndStatus _error;
// GET: Details
public ActionResult Index(TimeIntervalAndStatus error)
{
var detailsViewModel = new DetailsViewModel
{
QueryStartDate = error.TimeStart,
QueryEndDate = error.TimeEnd
};
return View(detailsViewModel);
}
}
My DetailsViewModel
public class DetailViewModel
{
[DisplayFormat(DataFormatString = "{0:dd-MMM-yyyy}")]
public DateTime QueryStartDate { get; set; }
[DisplayFormat(DataFormatString = "{0:dd-MMM-yyyy}")]
public DateTime QueryEndDate { get; set; }
public TimeSpan DetailDownTimeDuration { get; set; }
}
My Details.cshtml
@model Foo.Models.DetailViewModel
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Down-time details</title>
<script type="text/javascript">
</script>
</head>
<body>
<div>
</div>
</body>
</html>
So, what I need is access to the error object the Html.ActionLink passes so i can set the fields on the DetailsViewModel to those TimeStart, TimeEnd and Duration. I will then use this information to retrieve other information. This part works, but I also need access to the @Model.SummaryInformation.Name. So I want to pass two things.
I don't want to add the Name to the TimeIntervalAndStatus as it doesn't make sense for that object to have the summary Name.
Perhaps I shouldn't be using an @Html.ActionLink, is there a better way to do this?
I have tried making my ActionLink this
@Html.ActionLink("Details", "Index", "Details", new { error, kpiName = Model.SummaryInformation.Name}, null)
Then my controller method becomes
public ActionResult Index(TimeIntervalAndStatus error, string kpiName)
{
}
But then error is always null.
new {error, kpiName= Model....}http://localhost:54816/Details?error=Foo.Models.TimeIntervalAndStatus&kpiName=APSnew {TimeIntervalAndStatus = { TimeStart = error.TimeStart , TimeEnd = error.TimeEnd} , kpiName = Model.SummaryInformation.Name }