Switch out site images daily
So, we are going to be creating a view that has interchangeable images.
Basically, this开发者_开发知识库 process is automated to the point where we can log on to the admin site, click a button, and that button grabs the next set of images and changes the src
attribute of all the images already on the page.
Problem is, we want this to run daily every 24 hours, but I'm not sure how to set that up. MVC is stateless, so we wouldn't be able to put a timer in the controller, and if we had say a SQL Job setup, I'm not sure how the site would be notified of that event - if that route is even possible.
What's one way I can do this?
You should look up the paths from SQL Server inside the controller every time you request the page.
Have your ASP.NET script set the src
attributes dynamically:
<img id="place1" src="<%
int day = DateTime.Now.Day;
string[] images = {"images/image1_place1.jpg", "images/image2_place1.jpg", "etc.jpg"};
Response.Write(images[day % images.Length]);
%>" />
Or something along those lines.
Why would you change the src
tags... You know what the date is in your controller, just pass the images to the view inside your model (create a view model if you're only sending an array of items).
精彩评论