I have an asp.net mvc3 C# application. It uses a database. The database supports a soft-delete scenario due to requirements. The soft-delete scenario does not cascade. Records which have been flagged as deleted will be showed as grayed out. My issue is with how to do this without having to always surround each display from the model with some html markup and style.
For example:
<span @if(m.Box.isDeleted){
<text>style="background-color:gray"</text>
}>@m.Box.Name @m.Box.Description</span>
I can do that, but look at all the extra markup I have to do to literally every ViewModel object display.
What I would like to do is @m.Box.Name.AddMarkup() or something to that extent. Perhaps I could make a helper which took the item and then returned the correct markup such as
namespace place.Markup
public class Markup
{
public ModelItem(object o, property name)
{
//perhaps use reflection so the flag isnt passed all the time
//create markup with flag conditional decoration
//return markup
}
}
and then
@Markup.ModelItem(@m.Box.Description)
I am not sure how I should approach this, or if either of the suggested ways is how others approached this issue. What have you tried to display soft-deleted items? Is there a good tutorial for this somewhere? I couldn’t really find much material on this subject.
Please note: the filtering of these objects is not an issue, they are intentionally being displayed and they need to be displayed in a manner which reflects the soft-delete.
I would make an htmlHelper based on one or many overloads of DisplayFor
Something like