SlideShare a Scribd company logo
1 of 4
ASP.NET MCV used for Saving Data on the Client (Part 2)
VISIT: http://crbtech.in/Dot-Net-Training/
Booting up and Updating the Store :
The information you store in localStorage is on a route like how you store information in a
word reference: You develop a key and pass the key and your information to
localStorage’s setItem technique. This code recovers a reference to localStorage and
utilizes it to include the string “Subside Vogel” under the key “A123″:
var ls;
ls = localStorage;
ls.setItem(“A123″, “Peter Vogel”);
By using localStorage, you can pass numbers or strings as keys or information in any case,
at last, everything (keys and information alike) is kept away as strings.
With a specific end goal to keep every application’s information particular, instead of
developing different keys for every application, the more quick-witted arrangement is to
make a JSON object that holds every one of the information for a requested application.
You can then store that JSON object under an extraordinary name for the application.
You could develop that JSON object in JavaScript code running on the client in any case, in
any event, you ought to introduce the application’s customer side information with
information went from the server the first run through the client gets to your page. In the
event that you make that underlying item about as vast as it will ever get, you can likewise
utilize this to watch that you have enough room in localStorage for your application.
The principal thing to do in this way is to check if your application’s JSON element is now
present by endeavoring to recover it from localStorage utilizing localStorage’s getItem
capacity. In the event that the key you’re utilizing isn’t available, getItem won’t raise a
special case yet will, rather, give back an invalid worth. When you do understand that
invalid quality, you can store your underlying JSON information in localStorage.
Assembling that all in a View, this code verifies whether there’s any information put away
under the key “CustomerApplication” and places it in the variable custStr. In the event that
isn’t there, the code stores the item from the View’s Model property in localStorage by
changing it into a string. Once the information is securely kept aside, the code recovers the
information into the custStr variable.
var custStr
custStr = ls.getItem(“CustomerApplication”);
if (custStr == null)
{
try {ls.setItem(“CustomerApplication”, ‘@Html.Raw(Json.Encode(Model))’);}
catch(e) {alert(“Insufficient space”);}
custStr = ls.getItem(“CustomerApplication”);
}
The single quotes around the second parameter that went to the setItem capacity are required
to maintain a strategic distance from clashes with the twofold quotes utilized by the
Since the information has been recovered from localStorage, you can
change it into a JSON element to utilize somewhere else in your
application:
custJson = JSON.parse(custStr);
On the off chance that, as opposed to utilizing a hardcoded string as the
information is vital, you would rather utilize a few information from the
article, then the code is just somewhat more confused. This code stores
the element in the Model property utilizing the estimation of one of the
properties of the article as the key:
ls.setItem(“@Model.CustId”, ‘@Html.Raw(Json.Encode(Model))’);
Sparing the JSON object back to localStorage after it’s been changed in
the program requires even less exertion. This code redesigns a quality
in the JSON object, changes over the article back to a string and after
that overhauls localStorage with the outcome:
custJson.Customers[0].LastName = “Irvine”;
ls.setItem(“CustomerApplication”, JSON.stringify(custJson));
You may likewise need to utilize this JSON object for another
preparing. As discussed the procedures for sparing JSON, utilizing it as
This can be supported by utilizing the window’s article’s
AddEventHandler capacity to include an event handler for
“capacity.” However, you can’t attach the event to a
particular key in localStorage – the event is raised by a
change to anything in localStorage. Since different
applications may utilize localStorage (modernize utilizes
localStorage, for instance), it needs to be verified what key
sets off the event before you react to it.
The capacity you keep in touch with handle the event –
passes a parameter that has two properties that can help to
figure out if it needs to react: key and URL. The key
property contains the key to the thing that was changed; the
URL property contains the full URL of the page in which
the code is running.
The parameter went to your event handler, additionally
contains two different properties that hold information

More Related Content

Recently uploaded

The basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxThe basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptx
heathfieldcps1
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 

Recently uploaded (20)

How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17
 
II BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING II
II BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING IIII BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING II
II BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING II
 
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
The basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxThe basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptx
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
 Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
 
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
 
IPL Online Quiz by Pragya; Question Set.
IPL Online Quiz by Pragya; Question Set.IPL Online Quiz by Pragya; Question Set.
IPL Online Quiz by Pragya; Question Set.
 
Championnat de France de Tennis de table/
Championnat de France de Tennis de table/Championnat de France de Tennis de table/
Championnat de France de Tennis de table/
 
Software testing for project report .pdf
Software testing for project report .pdfSoftware testing for project report .pdf
Software testing for project report .pdf
 
demyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptxdemyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptx
 
Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).
 
The Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. HenryThe Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. Henry
 
HVAC System | Audit of HVAC System | Audit and regulatory Comploance.pptx
HVAC System | Audit of HVAC System | Audit and regulatory Comploance.pptxHVAC System | Audit of HVAC System | Audit and regulatory Comploance.pptx
HVAC System | Audit of HVAC System | Audit and regulatory Comploance.pptx
 
size separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticssize separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceutics
 
Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"
Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"
Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"
 

Featured

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Asp.net mcv used for saving data on the client (part 2)

  • 1. ASP.NET MCV used for Saving Data on the Client (Part 2) VISIT: http://crbtech.in/Dot-Net-Training/ Booting up and Updating the Store : The information you store in localStorage is on a route like how you store information in a word reference: You develop a key and pass the key and your information to localStorage’s setItem technique. This code recovers a reference to localStorage and utilizes it to include the string “Subside Vogel” under the key “A123″: var ls; ls = localStorage; ls.setItem(“A123″, “Peter Vogel”); By using localStorage, you can pass numbers or strings as keys or information in any case, at last, everything (keys and information alike) is kept away as strings. With a specific end goal to keep every application’s information particular, instead of developing different keys for every application, the more quick-witted arrangement is to make a JSON object that holds every one of the information for a requested application. You can then store that JSON object under an extraordinary name for the application.
  • 2. You could develop that JSON object in JavaScript code running on the client in any case, in any event, you ought to introduce the application’s customer side information with information went from the server the first run through the client gets to your page. In the event that you make that underlying item about as vast as it will ever get, you can likewise utilize this to watch that you have enough room in localStorage for your application. The principal thing to do in this way is to check if your application’s JSON element is now present by endeavoring to recover it from localStorage utilizing localStorage’s getItem capacity. In the event that the key you’re utilizing isn’t available, getItem won’t raise a special case yet will, rather, give back an invalid worth. When you do understand that invalid quality, you can store your underlying JSON information in localStorage. Assembling that all in a View, this code verifies whether there’s any information put away under the key “CustomerApplication” and places it in the variable custStr. In the event that isn’t there, the code stores the item from the View’s Model property in localStorage by changing it into a string. Once the information is securely kept aside, the code recovers the information into the custStr variable. var custStr custStr = ls.getItem(“CustomerApplication”); if (custStr == null) { try {ls.setItem(“CustomerApplication”, ‘@Html.Raw(Json.Encode(Model))’);} catch(e) {alert(“Insufficient space”);} custStr = ls.getItem(“CustomerApplication”); } The single quotes around the second parameter that went to the setItem capacity are required to maintain a strategic distance from clashes with the twofold quotes utilized by the
  • 3. Since the information has been recovered from localStorage, you can change it into a JSON element to utilize somewhere else in your application: custJson = JSON.parse(custStr); On the off chance that, as opposed to utilizing a hardcoded string as the information is vital, you would rather utilize a few information from the article, then the code is just somewhat more confused. This code stores the element in the Model property utilizing the estimation of one of the properties of the article as the key: ls.setItem(“@Model.CustId”, ‘@Html.Raw(Json.Encode(Model))’); Sparing the JSON object back to localStorage after it’s been changed in the program requires even less exertion. This code redesigns a quality in the JSON object, changes over the article back to a string and after that overhauls localStorage with the outcome: custJson.Customers[0].LastName = “Irvine”; ls.setItem(“CustomerApplication”, JSON.stringify(custJson)); You may likewise need to utilize this JSON object for another preparing. As discussed the procedures for sparing JSON, utilizing it as
  • 4. This can be supported by utilizing the window’s article’s AddEventHandler capacity to include an event handler for “capacity.” However, you can’t attach the event to a particular key in localStorage – the event is raised by a change to anything in localStorage. Since different applications may utilize localStorage (modernize utilizes localStorage, for instance), it needs to be verified what key sets off the event before you react to it. The capacity you keep in touch with handle the event – passes a parameter that has two properties that can help to figure out if it needs to react: key and URL. The key property contains the key to the thing that was changed; the URL property contains the full URL of the page in which the code is running. The parameter went to your event handler, additionally contains two different properties that hold information