I am currently developing a website that allows users to customise various aspects of it.
I have been able to upload, retrieve and cache custom css rules, and also images, however strings are eluding me. I am using ASP.net MVC5.
Here is the code I have so far:
FileController:
[HttpGet]
[OutputCache(Duration = 3600, Location = OutputCacheLocation.Server)]
public ContentResult getString()
{
string randString = getStringFromDatabase(); //retrieves hard coded string for now
if (randString != null && randString.Length > 0)
return Content(randString);
else
return null;
}
Then with this controller, I am planning to use @Url.Action to call the above method in FileController and retrieve the string. I have previously been able to retrieve images (since you put url action in the src attribute of the img tag) and also load custom CSS file (since you put url action in the src attribute of the link tag) both of these are cacheable with similar code to the above.
I achieve this with images like this:
<img class="navbar-logo" src="@Url.Action( "image", "file", new { name = "Logo.png" })" />
and would like to do this with strings.
I did attempt using a jQuery $.get function, but then it doesnt cache the string and loads the string after every page load.
If it helps, I am trying to save a custom page title in the database, then retrieve it on first load, and cache it.
TL;DR: I have a string stored in a database. I want to retrieve this string through a razor action (Url.Action or others) and show it to the user of the webpage. I also want to cache it. I can do it with images and css files because <img>
and <link>
tags both have src attributes, but <p>/<span>
and other text elements do not.
If you need any more information, just let me know!