NHaml 中的强类型视图?
我有一个强类型视图,想在 NHaml 页面中使用它。
使用 WebForms 引擎,我将在 <%@ Page%> 指令或代码隐藏文件中描述 ViewData 类型。
在 NHaml 中我该如何处理呢?
I have a strongly typed view and want to use it in an NHaml page.
With the WebForms engine I would describe the ViewData type in the <%@ Page%>
directive or in the codebehind file.
How would I go about that in NHaml?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Boris
如果我理解正确的话,你只是想拥有一个强类型的 nhaml 视图?
如果是这种情况,svn 中有一个示例项目可以执行此操作。请查看
http://nhaml.googlecode.com/svn/trunk/src 和 NHaml.Samples.Mvc.CSharp 项目
这是一些提取的代码
Controller
View
View Model
希望有帮助
Boris
If I understand correctly you just want to have a strong typed nhaml view?
If this is the case there is a sample project in svn that does this. Have a look at
http://nhaml.googlecode.com/svn/trunk/src and the NHaml.Samples.Mvc.CSharp project
And here is some extracted code
Controller
View
View Model
Hope that helps
在 此 页面上有一个补丁(搜索 NHaml)可以执行此操作。我不知道它是否有效。这需要来自 MvcContrib 的 NHaml。
On this page there's a patch (search for NHaml) to do this. I don't know if it works. This requires NHaml from MvcContrib.
您不需要这样做。您可以仅使用模型而不指定其类型,它就会起作用。例如:
这是因为 NHAML 视图被编译。因此,当模型上的所有属性都正确(名称、类型等)时,视图将被编译(如源代码一样)。
You don't need to do it. You can just use the Model without specifying its type and it will work. For example:
This is because the NHAML view gets compiled. So when all the properties on the Model are correct (names, types etc) the view will be compiled (as source code would).