I’m trying to learn ASP.NET MVC 3 with razor and so far getting the hang of it.
one thing I’m stuck on is trying to getting multiple data calls to work.
a background to what I’m doing. I have a page that will show info about a project(which i got working) but i also want to show the progress of that project(which is another data call). I can’t get the progress data to show. i tried using viewbag, but got:
System.Data.Objects.ObjectResult`1[System.String]
I’m using stored procedures with the Entity Framework.
I appreciate the help guys.
EDIT:
Here is a rough example of my problem:
private SDMPREntities _db = new SDMPREntities();
public ActionResult Details(int id) {
ViewData.Model = _db.ViewProjectDetails(id).ToList();
ViewBag.Progress = _db.ProjectProgress();
return View();
}
EDIT2:
@James D’Angelo, yes in the view. Heres the razor code:
@model IEnumerable<DeveloperManagerSharp.Models.Projects>
@{
ViewBag.Title = "Project Details";
Layout = "~/Views/Shared/project-ui.cshtml";
}
<div class="post">
<h3 class="title">
Project Details</h3>
<div class="entry">
<h4>
Select a Project</h4>
<p>
Select a project below to see their progress or to update any of their properties.</p>
</div>
</div>
@foreach (var item in ViewData.Model)
{
<div class="post">
<h3 class="title">@item.project_name (@item.project_version) @ViewBag.Progress%</h3>
<div class="meta">
<div class="posted">
@Html.ActionLink("Edit", "Edit", new { id = item.PID }) |
@Html.ActionLink("Back to Projects", "Index")
</div>
@if (@item.project_completed == "1") {
<div class="date">
Project is Completed.
</div>
} else {
<div class="date">
Project is Under Work.
</div>
}
</div>
<div class="entry">
@if(@item.project_status == "0")
{
<span>Status: Planning</span><br />
}
else if(@item.project_status == "1")
{
<span>Status: Alpha</span><br />
}
else if(@item.project_status == "2")
{
<span>Status: Beta</span><br />
}
else if(@item.project_status == "3")
{
<span>Status: Release Candiate</span><br />
}
else if(@item.project_status == "4")
{
<span>Status: Active</span><br />
}
else if(@item.project_status == "5")
{
<span>Status: Maure</span><br />
}
else if(@item.project_status == "6")
{
<span>Status: Discontinued</span><br />
}
Starts: @item.project_sdate<br />
Ends: @item.project_edate<br />
<em>@item.project_desc</em>
</div>
</div>
}
The call
Is most likely returning an ObjectResult, which represents a collection of items.
So when you tried to display it in the view with
ToString() is being called, which simply prints out the type.
To get around this, you want to fetch a specific result from the set. Without knowing your data structure I can only hazard a guess, e.g.