簡體   English   中英

ASP.NET MVC3 C# - 當用戶單擊按鈕時,將DB中的記錄從1更改為2,反之亦然

[英]ASP.NET MVC3 C# - when user clicks button, change record in DB from 1 to 2 and viceversa

基本上是按鈕功能,可以更改數據庫中記錄中的數據。

偽:

如果在DB = 1中記錄,則在按鈕單擊時,如果在DB = 2中記錄,則更改為2 Else,在按鈕單擊時,更改為1

提前感謝您的任何提示/幫助

艾米你可以編輯你的問題並在那里發布代碼並應用適當的格式。

因為它是您的第一個網絡應用程序,它是您正在尋找的提示/幫助:

  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();
 }
}

這樣的事情。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM