@model IEnumerable<DateTime>
<table>
@foreach(var date in model)
{
<tr>
<td>@date</td>
</tr>
}
</table>
public class Person
{
public int Id {get;set;}
public string Name {get;set;}
public string SurName {get;set;}
public IEnumerable<DateTime> LoginDates {get;set;}
}
public ActionResult Index(int id)
{
var person = context.Persons.Where(x=>x.Id == id).Select(x=>new Person{x.Id, x.Name, x.Surname}).FirstOrDefault();
//Notice that i only get the id, name and surname from the table using EF. I will call the procedure to fill in the dates
if(person!=null)
{
var myintparam = new SqlParameter
{
ParameterName = "myParam",
Value = id
};
person.LoginDates = context.Database.SqlQuery<DateTime>("dbo.MyStoredProcedureName @myParam").ToList();
}
return View(person);
}
@model Person
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
<table>
<tr>
<td>Person Id : </td><td>@Model.Id</td>
<td>Person Name : </td><td>@Model.Name</td>
<td>Person Surname : </td><td>@Model.SurName</td>
</tr>
</table>
<h1>Login Dates</h1>
@Html.DisplayFor(m => m.LoginDates, "MyDateTimes")
public class Person
{
public int Id {get;set;}
public string Name {get;set;}
public string SurName {get;set;}
[UIHint("MyDateTimes")]
public IEnumerable<DateTime> LoginDates {get;set;}
}
@Html.DisplayFor(m => m.LoginDates)
EF has a means of running an SP and even define the kind of data you expect from it.
Let's suppose you have name your db context as "context". This has a property named "Database", which in itself has a method "SqlQuery", which accepts a string as the sql string you want to run against your db and a string array that will represent the params to send to the sql string.
In your case you could run something like:
Open in new window
You may return the "results" in your View as you would normally do.
Giannis