你好的人,我有以下代码:外键不填充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