Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.SessionState; //for session
- using System.Web.UI;
- namespace SessionPractice.Models
- {
- public sealed class HttpSessionState
- {
- public string FirstName { get; set; }
- public string LastName { get; set; }
- public int QuantityOrdered { get; set; }
- public int QuantityTotal { get; set; }
- }
- public class UserSession1
- {
- public string FirstName { get; set; }
- public string LastName { get; set; }
- public int QuantityOrdered { get; set; }
- public int QuantityTotal { get; set; }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using System.Web.SessionState; //for session
- using System.Web.UI; //for cache
- using SessionPractice.Models;
- namespace SessionPractice.Controllers
- {
- [SessionState(SessionStateBehavior.Default)]
- public class SessionPracticeController : Controller
- {
- void Session_Start (object sender, EventArgs e) //?
- {
- }
- // GET: SessionPractice
- public ActionResult Session1()
- {
- UserSession1 model = new UserSession1();
- return View(model);
- }
- [OutputCache(Duration = 30, Location = OutputCacheLocation.Client, VaryByParam = "none")]
- public ActionResult FormSubmit(UserSession1 sp)
- {
- UserSession1 cache = new UserSession1();
- return View(sp);
- }
- void Session_End(object sender, EventArgs e)
- {
- }
- }
- }
- namespace SessionPractice.Cache
- {
- public class UserSession1
- {
- public int QuantityTotal { get; set; }
- }
- }
- @{
- Layout = null;
- }
- <!DOCTYPE html>
- <html>
- <head>
- <meta name="viewport" content="width=device-width" />
- <script>
- Session["FirstName"] = FirstName;
- Session["LastName"] = LastName;
- Session["QuantityOrdered"] = QuantityOrdered;
- Session["QuantityTotal"] = QuantityTotal;
- var FirstName = (String)(Session[FirstName]);
- var LastName = (String)(Session[LastName]);
- var QuantityOrdered = (Int)(Session[QuantityOrdered]);
- var QuantityTotal = (Int)(Session[QuantityTotal]);
- </script>
- <title>Session1</title>
- </head>
- <body>
- <h2>Please fill out the following form.</h2>
- <form method="post" action="FormSubmit" onsubmit="return(sp) ">
- First Name:
- <br />
- <input id="FirstName" type="text" name="FirstName">
- <br />
- Last Name:
- <br />
- <input id="LastName" type="text" name="LastName">
- <br />
- Quantity Ordered:
- <br />
- <input id="QuantityOrdered" type="text" name="QuantityOrdered" />
- <br />
- <br />
- <br />
- <input type="submit" value="Submit"/>
- </form>
- </body>
- </html>
- @model SessionPractice.Models.UserSession1
- @{
- Layout = null;
- }
- @if (Model != null)
- {
- <span>First Name:</span>
- <span>@Model.FirstName</span>
- <br />
- <span>Last Name:</span>
- <span>@Model.LastName</span>
- <br />
- <span>Quantity Ordered:</span>
- <span>@Model.QuantityOrdered</span>
- <br />
- <span>Total Quantity Ordered (so far):</span>
- <span>@Model.QuantityTotal</span>
- <br />
- }
- @if (Cache !=null)
- {
- var QuantityOrdered = Cache.Count; //?
- for (int QuantityTotal = 0; QuantityOrdered < QuantityTotal++; )
- {
- <br />
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement