开发者

How to get SINGLE value from ViewBag or ViewData

I have this:

_gameService = new GameService();
            ViewBag.Data = _gameService.JoinGame(userID, gameID, whoJoin);
            return View("Game");

This code gets list of users that are ingame, and pass it to game view. Nothing fancy.

On the game view I need to get single values from ViewBag 开发者_如何转开发in diffrent places, like UserID, GameID, Moves etc.

Using Strongly Typed view is not an option, because I need list of users that are in game, and strongly-typed view give me only option to store single user(which won't work in multiplayer game)


You should really use strongly typed views. Here is small intro. They are really more flexible. You can create class like PlayerList with a field of List type and then iterate it in your view (Explanation). And here is explanation how to pass strongly typed lists to View.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜