你好的人,我有以下代碼:外鍵不填充MVC3
public ActionResult Create(GameTBL gametbl)
{
if (ModelState.IsValid)
{
//First you get the gamer, from GamerTBLs
var gamer = db.GamerTBLs.Where(k => k.UserName == User.Identity.Name).SingleOrDefault();
//Then you add the game to the games collection from gamers
gamer.GameTBLs.Add(gametbl);
db.SaveChanges();
return RedirectToAction("Index");
}
}
這是給我下面的錯誤:
Error 1 'MvcApplication1.Controllers.GameController.Create(MvcApplication1.Models.GameTBL)': not all code paths return a value
這段代碼是試圖做的是試圖填充玩家的外鍵進入遊戲桌
模型我的控制器玩家:
public string UserName { get; set; }
public int GamerID { get; set; }
public string Fname { get; set; }
public string Lname { get; set; }
public string DOB { get; set; }
public string BIO { get; set; }
我的遊戲控制器
型號:
public int GameID { get; set; }
public string GameName { get; set; }
public string ReleaseYear { get; set; }
public string Cost { get; set; }
public string Discription { get; set; }
public string DownloadableContent { get; set; }
public string Image { get; set; }
public string ConsoleName { get; set; }
public int GamerIDFK { get; set; }
public byte[] UserName { get; set; }
我會試着讓你知道,謝謝 – user1137472 2012-03-26 23:44:58
如果我理解正確,你仍然試圖填充你的控制器模型的「GamerIDFK」屬性,仍然沒有從玩家表中填充外鍵到遊戲表 – user1137472 2012-03-26 23:50:51
@ user1137472?你可以發表你的看法代碼,看看你與此GamerIDFK屬性在視圖中做什麼...... – NiK 2012-03-27 14:59:19