EDIT - I have made progress from the original post and have now made the relevant changes to the question.
In the controller I now have a variable called lstSteps that brings in all the details of the steps that are associated with the relevant Execution.
The problem now is that I am unable to show this list of Steps in the Execution view. I understand that I need to write a foreach loop but cant figure out how to write it.
Controller
public ActionResult Execution(int id = 0)
{
Execution execution = db.Executions.Find(id);
var lstSteps = db.Steps.Where(z => z.Execution.Id == id).ToList();
if (execution == null)
{
return HttpNotFound();
}
ViewBag.ExecutionSeconds = (execution.End - execution.Start).ToString(@"dd\.hh\:mm\:ss\.fff");
return View(execution);
}
Execution Model
namespace DataIntelligence.Models
{
[Table("Execution")]
public class Execution
{
public int Id { get; set; }
public Int16 PackageId { get; set; }
public DateTime Start { get; set; }
public DateTime End { get; set; }
public Boolean Successful { get; set; }
}
}
Step Model
namespace DataIntelligence.Models
{
[Table("Step")]
public class Step
{
public int Id { get; set; }
public int ExecutionId { get; set; }
public string Name { get; set; }
public DateTime Date { get; set; }
public virtual Execution Execution { get; set; }
}
}
Execution View
@model DataIntelligence.Models.Execution
@{
ViewBag.Title = "Execution Details";
}
<script language="javascript" type="text/javascript" src="jquery-1.8.3.js"> </script>
<script>
function goBack() {
window.history.back();
}
</script>
<div class="jumbotron">
<h2>Execution Details</h2>
</div>
<fieldset>
<legend>Execution Id - @Html.DisplayFor(model => model.Id)</legend>
<div class="row">
<div class="col-sm-3">
<div class="display-label">
@Html.DisplayNameFor(model => model.PackageId)
</div>
<div class="display-field">
<a href="@Url.Action("Package", new { id=Model.PackageId})"> @Html.DisplayFor(model => model.PackageId) </a>
</div>
</div>
<div class="col-sm-3">
<div class="display-label">
@Html.DisplayNameFor(model => model.Start)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.Start)
</div>
</div>
<div class="col-sm-3">
<div class="display-label">
@Html.DisplayNameFor(model => model.End)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.End)
</div>
</div>
<div class="col-sm-3">
<div class="display-label">
Execution Time
</div>
<div class="display-field">
@ViewBag.ExecutionSeconds
</div>
</div>
</div>
<div class="row">
<div class="col-sm-3">
<div class="display-label">
@Html.DisplayNameFor(model => model.Successful)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.Successful)
</div>
</div>
</div>
<br />
</fieldset>
<table>
<tr>
<th>
Step ID
</th>
<th>
Name
</th>
<th>
Date
</th>
</tr>
@foreach (var ? in ?) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td style="width: 600px;">
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Date)
</td>
</tr>
}
</table>
<button class="btn btn-link" onclick="goBack()" style="padding-right: 0px; padding-top: 0px; padding-bottom: 0px; padding-left: 0px;">Back</button>
I believe the parts I am going wrong on is where I have placed the ?
Help would be much appreciated.
Thanks in advance.
Stepmodel has a list ofExecution. Should yourExecutionhave a list of Steps? Once you have a list of 'Step' you can use@foreach(var step in Model.Steps) { // code }