为什么这是循环的
本文关键字:循环 为什么 | 更新日期: 2024-10-31 00:00:21
我遇到了有趣的问题。首先单击我的部分视图提交时一切正常。它进入数据库并保存我的记录。但是,如果我第二次单击它(当第一次单击将结束他的工作时),它会两次并保存两次所有内容。下次单击上一个 * 2。 任何人都可以解释发生了什么?
这是Facebook应用程序,但我不认为这是fb问题
我的控制器是:
KubetiDbContext db = new KubetiDbContext();
public ActionResult Index()
{
string request = Session["signed_request"].ToString();
FaceBook client = new FaceBook();
FBuserinfo user = new FBuserinfo();
SignedRequest sr = client.parseSignedRequest(request);
var db_user = (from a in db.Users
where a.fbId == sr.user_id
select a).FirstOrDefault();
ViewBag.ID = db_user.id;
//var participants = from q in db.fifthWeekBids
var laptop = (from a in db.Laptops
select a).FirstOrDefault();
ViewBag.countLeft = laptop.countLeft;
return View();
}
[HttpGet]
public ActionResult Bet()
{
var laptop = (from a in db.Laptops
select a).FirstOrDefault();
ViewBag.startPrice = laptop.startPrice;
return YourPlace();
}
[HttpPost]
public ActionResult Bet(string code)
{
string request = Session["signed_request"].ToString();
FaceBook client = new FaceBook();
FBuserinfo user = new FBuserinfo();
SignedRequest sr = client.parseSignedRequest(request);
var db_user = (from a in db.Users
where a.fbId == sr.user_id
select a).FirstOrDefault();
using (KubetiDbContext _db = new KubetiDbContext())
{
firstWeekBid fw = new firstWeekBid();
fw.userId = db_user.id;
fw.bidCount = int.Parse(code);
fw.dateOfBid = DateTime.Now;
_db.firstWeekBids.Add(fw);
_db.SaveChanges();
}
if (Request.IsAjaxRequest())
{
if (ViewData["IsAjax"] == null || (bool)ViewData["IsAjax"] != false)
{
ViewData["IsAjax"] = true;
}
return Bet();
}
return View();
}
public ActionResult YourPlace()
{
return View();
}
视图:
<div class="bigBgPaper">
<div id="regLogo"></div>
<div id="regAucHead"></div>
<div id="rightRed">
</div>
<nav class="mainNav">
@Html.ActionLink("ჩემი პროფილი", "Index", "Profile")
<div class="smallKub"></div>
@Html.ActionLink("პრიზები", "Index", "Prizes")
<div class="smallKub"></div>
@Html.ActionLink("აუქციონი", "Index", "Auction", null, new { @style = "color:red;" })
<div class="smallKub"></div>
@Html.ActionLink("გამარჯვებულები", "Index", "Winners")
</nav>
<div class="auqcPrize">
<div class="prizeOverflow">
<div class="prizePic"></div>
<div class="prizeLeft"><p>@ViewBag.countLeft</p></div>
</div>
<span>Lenovo</span>
<br />
<span>IdeaPad G50-30</span>
<br />
<span>CPU: 2160</span>
<br />
<span>RAM: 2GB</span>
</div>
<div id="monaw">
<span>მონაწილეები</span>
<div id="monawline"></div>
</div>
<div id="cowndtdownDIv">
<span>დასრულებამდე</span>
<div id="timer"></div>
</div>
<div id="betdiv">
@Html.Partial("Bet")
</div>
和部分视图:
@model Kubeti.Models.Codes
@if (ViewData["IsAjax"] != null && (bool)ViewData["IsAjax"] == true)
{
ViewData["IsAjax"] = false;
}
else
{
<span>შეიყვანეთ თქვენი ფსონი</span>
using (Ajax.BeginForm("Bet", new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "pozition", InsertionMode = InsertionMode.Replace }))
{
@Html.EditorFor(x => x.code)
@Html.ValidationMessageFor(x => x.code)
<input type="submit" value="OK" />
}
<span id="minBet">დასადები ფსონის მინიმალური რაოდენობა: @ViewBag.startPrice</span>
<span id="pozition">თქვენი პოზიცია: </span>
}
您在分部视图中有Ajax.BeginForm
。这将导致每次调用时,表单提交,控制器输出另一个表单,该表单将嵌套在父表单中。
这将通过提交您包含提交按钮的每个表单来在您的 html 上导致奇怪的行为。