ASP.当用户单击按钮时,将DB中的记录从1更改为2,反之亦然

本文关键字:记录 反之亦然 单击 用户 按钮 DB ASP | 更新日期: 2023-09-27 18:04:33

基本上是一个按钮功能,用于更改数据库中记录中的数据。

伪:

如果记录在DB = 1, on按钮点击,更改为2否则,如果记录在DB = 2,点击按钮,更改为1

提前感谢任何提示/帮助

ASP.当用户单击按钮时,将DB中的记录从1更改为2,反之亦然

Amy,你可以编辑你的问题并在那里发布代码,并应用适当的格式。

因为它是你的第一个web应用程序,它是提示/帮助你正在寻找:

  1. http://www.asp.net/mvc/tutorials/getting-started-with-mvc3-part1-cs
  2. http://weblogs.asp.net/scottgu/archive/2011/03/09/free-video-training-asp-net-mvc-3-features.aspx
  3. http://msdn.microsoft.com/en-us/library/gg416514 (v = vs.98) . aspx

这些链接将帮助您更好地了解web应用程序和MVC3 -在尝试这些教程后,如果有任何问题,请回到这里。

Sudo控制器动作。

public ActionResult DetailsChanged(DetailsRepository detailsRepository, Details detailsModel)
{
  if(!ModelState.Valid)
{
   ViewData["Error"] = "Error";
   return View();
}
Details newDetails = detailsRepository.FirstOrDefault(x => x.ID == detailsModel.Id);
if(newDetails != null)
{
   if(newDetails.Id == 1)
   {
      newDetails.Id = 2;
   } else {
      newDetails.Id = 2;
   }
   detailsRepository.SaveChanges();
   return View();
 }
}

差不多。