开发者

How does one access a ViewData item which contains a special character with the ViewBag?

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
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜