ASP.NET MVC Beta 1 - 它支持强类型视图数据吗?
在以前的版本中,有 3 种方法可以将数据从控制器传递到视图 AFAIK(如下所示)。
我想在 MVC Beta 1 中使用方法 (2),但找不到 renderView 方法。 那么新语法是什么(如果仍然可能)? 提前致谢。
本.
语法#1:老式字典
ViewData["Name"] = "Moo-moo";
ViewData["Age"] = 6;
ViewData["HasFunnyFace"] = true;
RenderView("ShowCat");
语法#2:显式类型的 ViewData 对象
RenderView("ShowCat", new ShowCatViewData {
Name = "Moo-moo",
Age = 6,
HasFunnyFace = true
});
语法#3:匿名类型的对象
RenderView("ShowCat", new {
Name = "Moo-moo",
Age = 6,
HasFunnyFace = true
});
In previous releases there were 3 ways to pass data from controller to view AFAIK (shown below).
I want to use method (2) with MVC Beta 1, but I can't find the renderView method. So what's the new syntax (if it's still possible)? Thanks in advance.
Ben.
Syntax #1: Old-school dictionary
ViewData["Name"] = "Moo-moo";
ViewData["Age"] = 6;
ViewData["HasFunnyFace"] = true;
RenderView("ShowCat");
Syntax #2: Explicitly-typed ViewData object
RenderView("ShowCat", new ShowCatViewData {
Name = "Moo-moo",
Age = 6,
HasFunnyFace = true
});
Syntax #3: Anonymously-typed object
RenderView("ShowCat", new {
Name = "Moo-moo",
Age = 6,
HasFunnyFace = true
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 beta 1 中,使用 View 方法:
View 方法取代了 RenderView 方法。
In beta 1, use the View method:
The View method has replaced the RenderView method.
根据 Kieron 的评论,在 Visual Studio 2008(也许是 2005/VSE?)中,当您右键单击控制器操作时,可以在上下文菜单顶部选择“添加视图”。
这会弹出一个小对话框,您可以通过指定它来创建强类型视图。
Following from Kieron's comment, in Visual Studio 2008 (maybe 2005/VSE?), when you right click on your controller action, you can choose 'Add View' at the top of the context menu.
This brings up a little dialog box, which will allow you to create a strongly typed view by specifying it.