Requirements: Mobile phone to open the details of a page, because of the speed or other reasons, the response is too slow, because the picture of the big reason, want to advanced, the picture in the page running situation and then slowly load (jquer delay load) http://www.w3cways.com/1765.html ()
Difficulty: Because the picture of the page is added in the editor
: Picture and text stored in a field in a database
: Implement the idea: Read this field from the database, replace the SRC in the field with Lazyload and return to the page
The main point here is how to replace the values in the fields in the data that are taken from the database and then convert the data directly to the page.
First of all
Public ActionResult Index (int id)
{
var model=new bll (). Getmodel (ID)
Model=replace (model)
Return model;//now returns the following: the SRC attribute in the database is changed to * * * *,
}
Expansion class for public model replace (model extension model)//pass in an entity
{
Two steps, depending on the situation, need not be
StreamReader reader = new StreamReader (model. ContentText, Encoding.UTF8);//Change the contents of a database field into a string
String AAA = Reader. ReadToEnd ();//Read All strings
String Aaa=model. Replace ("A", "B")//a is itself a string, B is a string that needs to be replaced
For example, string a= "ABCD" would turn into string a= "BBCD"
String bbb=model.pc the contents of the paragraph. Rep;ace ("A", "B");
MODEL.PC segment content = BBB;
Model. Mobile content = AAA;
Return model
}
Another step to the pit:
The reason is that the single quotation mark is a character, "" is to enclose a string, so the above "into" "just fine."
Because the value of the page is dynamically transmitted
So directly
Operation effect, has turned Src into data-original
Model. ContentText = bbb + " ";//The convenience test that is added directly in the text
Extract values from database fields and change + picture lazy loading, jquery lazy loading