A toy exam开发者_高级运维ple,
ViewData["rat"] = "Rodent";
var blaw = ViewBag.rat;
ViewData["dig/dug"] = "Game";
// var blaw2 = Viewbag.dig/dug;
The last line of course does not work. How would I access "dig/dug" through the ViewBag?
Just use underscore (or some another allowed symbol) instead of slash. Slash is not allowed:
ViewData["dig_dug"] = "Game";
Since ViewBag is dynamic dig/dug will be a property of dynamic object.
You can't use some special symbols(/,. etc..) within name of properties:
public string Dig\Dug {get;set;} // compilation time error
精彩评论