我正在静态会话类的会话中存储名称和地址。当一个客户打开支付屏幕时,我会在表格前填上姓名和地址。如果客户A打开信用卡屏幕,然后客户B打开同一屏幕,则客户B具有客户A的名称和地址。
我认为这是由于“静态”会话类引起的?如果是这样的话,我该怎么避免呢?
这是我的课程:
public static class MySession
{
public static string BranchNumber { set; get; }
public static string AccountNumber { set; get; }
public static string Name { set; get; }
public static string CustomerEmail { get; set; }
public static string Street { get; set; }
public static string Zip { get; set; }
public static string Zip4 { get; set; }
}
我的表格:
@model SssMobileIInquiry.Models.HomeModels.CreditCard
@{
ViewBag.Title = "Credit Card Payment";
}
<div class="container">
@using (Html.BeginForm("SubmitCreditCardCharge", "Home", FormMethod.Post))
{
<h4>Credit Card Payment</h4>
<div class="row">
<div class="col-sm-3">
Name
</div>
<div class="col-sm-9 focus">
@Html.TextBoxFor(m => m.NameOnCard, new { @class = "form-control" })
</div>
</div>
<div class="row">
<div class="col-sm-3">
Street
</div>
<div class="col-sm-9">
@Html.TextBoxFor(m => m.Street, new { @class = "form-control" })
</div>
</div>
<div class="row">
<div class="col-sm-3">
Zip Code
</div>
<div class="col-sm-9">
@Html.TextBoxFor(m => m.ZipCode, new { @class = "form-control", @maxlength = "9" })
</div>
</div>
<div class="row">
<div class="col-sm-3">
Card Number
</div>
<div class="col-sm-9">
@Html.TextBoxFor(m => m.CardNumber, new { @class = "form-control" })
</div>
</div>
<div class="row">
<div class="col-sm-3">
Expiration Date
</div>
<div class="col-sm-9 datefieldsmall">
@Html.TextBoxFor(m => m.ExpirationDateMonth, new { @class = "form-control", @maxlength = "2", @placeholder = "MM" })
</div>
<div class="col-sm-9 datefieldsmall">
@Html.TextBoxFor(m => m.ExpirationDateYear, new { @class = "form-control", @maxlength = "2", @placeholder = "YY" })
</div>
</div>
<div class="row">
<div class="col-sm-3">
CVV Number
</div>
<div class="col-sm-9">
@Html.TextBoxFor(m => m.PinNumber, new { @class = "form-control", @maxlength = "4" })
</div>
</div>
<div class="row">
<div class="col-sm-3">
Amount
</div>
<div class="col-sm-9">
@Html.TextBoxFor(m => m.PaymentAmount, new { @class = "form-control", @maxlength = "7" })
</div>
</div>
<div class="warning">
@Html.ValidationMessageFor(m => m.PaymentAmount)
</div>
<div class="row">
<input id="submitpayment" class="btn btn-primary btn-block buttonx accountinfobutton" type="submit" value="Submit" />
</div>
}
@using (Html.BeginForm("AccountInfo", "Home", FormMethod.Post))
{
<div class="row">
<input id="submitpayment" class="btn btn-primary btn-block buttonx accountinfobutton" type="submit" value="Account" />
</div>
}
</div>
我的行动结果是:
public ActionResult CreditCard()
{
if (MySession.CorporationId == Guid.Empty || string.IsNullOrEmpty(MySession.AccountNumber))
{
return View("Index");
}
var model = new Models.HomeModels.CreditCard();
model.NameOnCard = MySession.Name;
model.Street = MySession.Street;
model.ZipCode = MySession.Zip;
model.PaymentAmount = MySession.TotalBalance.Contains("-") ? "" : MySession.TotalBalance;
if (MySession.BudgetBalance.GetNumericValue() > 0 && MySession.BudgetRate.GetNumericValue() > 0)
{
model.PaymentAmount = MySession.BudgetBalance;
}
return View("CreditCard", model);
}
我正在用我的会话填充我的模型:
model.NameOnCard = MySession.Name;
model.Street = MySession.Street;
model.ZipCode = MySession.Zip;
我不知道为什么要为另一个登录的帐户显示客户信息。任何想法都会受到极大的赞赏。
谢谢你的帮助!