I have what should be a simple set of data from a table in SQL to a HTML.EditorFor helper. The problem I have is the records in the database are boolean values and I need to display a string of text depending on if the value is a 1 or a 0.
My Editor Template looks like this:
@model nData.DAL.tblTaggingGroupInstance
<td>
@Html.DisplayFor(modelItem => modelItem.WeekDay)
</td>
<td>
@Html.DisplayFor(modelItem => modelItem.Segment)
</td>
<td>
@Html.DisplayFor(modelItem => modelItem.NetSales)
</td>
<td>
@Html.DisplayFor(modelItem => modelItem.SwellSales)
</td>
<td>
@Html.DisplayFor(modelItem => modelItem.SpikeSales)
</td>
<td>
@Html.EditorFor(modelItem => modelItem.Recurring)
</td>
<td>
@Html.EditorFor(modelItem => modelItem.tblTaggingReasonID)
</td>
<td>
@Html.EditorFor(modelItem => modelItem.Comment)
</td>
My Model is:
public partial class tblTaggingGroupInstance
{
public int ID { get; set; }
public int tblTaggingGroupID { get; set; }
public int FinYear { get; set; }
public int FinWeek { get; set; }
public int WeekDay { get; set; }
public Nullable<int> tblTaggingReasonID { get; set; }
public Nullable<decimal> NetSales { get; set; }
public Nullable<decimal> SwellSales { get; set; }
public Nullable<decimal> SpikeSales { get; set; }
public string Comment { get; set; }
public string Segment { get; set; }
public Nullable<bool> Recurring { get; set; }
public Nullable<decimal> BaseSales { get; set; }
public virtual tblTaggingGroup tblTaggingGroup { get; set; }
}
And the Controller is
public ActionResult Index()
{
var SelectedID = Convert.ToInt32(Session["_SessionSelectGroupID"]);
var SelectedYear = Convert.ToInt32(Session["_SessionSelectFinYear"]);
var SelectedWeek = Convert.ToInt32(Session["_SessionSelectFinWeek"]);
var tblTaggingGroupInstances = db.tblTaggingGroupInstances.Include(t => t.tblTaggingGroup);
return View(tblTaggingGroupInstances.Where(t => t.tblTaggingGroupID == SelectedID && t.FinYear == SelectedYear && t.FinWeek == SelectedWeek).ToList());
}
[HttpPost]
public ActionResult Index(List<tblTaggingGroupInstance> model)
{
foreach (var record in model)
{
db.Entry(record).State = EntityState.Modified;
}
db.SaveChanges();
return RedirectToAction("Index");
}
What would be the simplest / easiest way to to change the text that is displayed without affecting the value that is posted back to the database?
Thanks Mark
Nullable<bool> Recurringproperty? What text do you want to display?null? One option would be to use a view model with an additionalstringproperty containing the text and include a hidden input for the property (but if you want to edit it and update the display text, then you will need javascript)dropdownin your title, but now in your code