1

In my main view i have following:

<body style="background-image: url(../Content/themes/base/images/sos.png)">

Instead of using string url here i want admin to have access to this url by using AdminModel. Something like this:

<body style="background-image: @AdminModel.BackgroundImage>

My AdminModel currently look like this:

public class AdminModel
    {
        public int DateId { get; set; }
        public DateTime Date { get; set; }
        public string BackgroundPath { get; set; }
    }

Where DateId and Date are fields of a DateTime table. I dont want to add BackgroundPath as a table field because it will only carry one value. So is there a better way to achieve this? So that admin can change background url when they want to?

NoviceMe
  • 3,126
  • 11
  • 57
  • 117
  • so, where do you imagine this field would be persisted if you don't want it to be a table field.? seems to me that you should really be saving this to the db, rather than trying all sorts of exotic solutions (saving to xml, texfiles, memory cache -shudder etc) to work around that very practice.! – jim tollan Aug 26 '12 at 16:49
  • jim tollan - So you think i should create another table with one field in it called BackgroundImage? That is what i was thinking but was not sure if this was right approach to create a whole table just for one field with one value in it? – NoviceMe Aug 26 '12 at 16:50
  • yeah, i think you should think out the entire admin requirement and have a table for anything that may be required thee. – jim tollan Aug 26 '12 at 16:52

1 Answers1

2

You will have to use something very similar to this:

<body style="background-image: url(@(AdminModel.BackgroundImage))">

On the other hand, you might want to use better (subjective) solution presented here: Action Image MVC3 Razor

Hope this helps

Community
  • 1
  • 1
Display Name
  • 4,672
  • 1
  • 33
  • 43