In the view, I have:
grid.Column("Complete", header: "Verified", format: (item) => @Html.Raw(item.Complete))
item.complete is an integer. I created an extension method to help display the corresponding string value since there are only 3 possibilities. Here is the extension method:
public static string CompleteValue(this int value)
{
switch (value)
{
case 0:
return "Submitted";
case 1:
return "Verified - Incomplete";
case 2:
return "Verified - Complete";
}
//Default if we get this far
return "Submitted";
}
I don't know how to write the Razor code to make it work. I have tried putting the ".CompleteValue" several places in the code but nothing works. Does anyone have any suggestions?
Edit: This is the view:
@model IEnumerable<SendMailwithAttachment.Models.MailModel>
@using System.Activities.Statements
@using Hazards
@using SendMailwithAttachment.Models;
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>My Hazards</h2>
<script src="~/Scripts/jquery-1.7.1.min.js"></script>
@{
var dataContext = new HazardsDataContext();
var getHazards1 = from m in dataContext.Mail
where (m.User == User.Identity.Name)
select new{m.casenum,m.ID,m.User,m.Date,m.To,m.name,m.Hazard,m.PictureDataAsByte,
m.Risk,m.AfterPicture,m.status,m.Complete};
var getHazards = from n in getHazards1
orderby n.Complete // Order by the Completed (or Verified Status so that verified reports show up last)
select n;
var grid = new WebGrid(source: getHazards);
if (getHazards.Count() > 0)
{
@grid.GetHtml(columns: new[] {
grid.Column("Casenum", header: "Case #"),
grid.Column("Date", header: "Date"),
grid.Column("Hazard", header: "Hazard"),
grid.Column("Before",header: "Before",format:
@<Text><img src="@Url.Content(item.PictureDataAsByte)" width="175" height="175" />
</text>),
grid.Column("Risk", header: "Risk"),
grid.Column("After",header: "After",format:
@<Text><img src="@Url.Content(item.AfterPicture)" width="175" height="175" />
</Text>),
grid.Column("status", header: "Status"),
//grid.Column("Complete", header: "Verified", format:(item) => (item.Complete))
grid.Column("Complete", header: "Verified", format: (item) => @Html.CompleteValue(item.Complete))
//grid.Column("Complete", header: "Verified", format: (item) => @Html.Raw("<input type='checkbox' " + ((item.Complete==0) ? "checked" : "") + " disabled='disabled' />")),
})
}
else
{
@Html.Raw("No Data Found")
}
}