ASP.NET MVC视图-我可以使用代码隐藏 [英] ASP.NET MVC Views - Can I use code-behind

查看:56
本文介绍了ASP.NET MVC视图-我可以使用代码隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是MVC的新手,并且注意到所有混合了脚本标记的视图页面看起来都非常讨厌.在视图代码背后的方法中生成HTML,然后将方法的字符串结果作为单个脚本插入,是否有意义?

I am new to MVC and I notice that the view pages can look pretty nasty with all the intermixed script tags. Does it make sense to generate the HTML in a method in the view code-behind and then just insert the string result of the method as a single bit of script?

例如:<div><%= GenerateTonsOfHTMLFromSomeIEnumerable() %></div>

这与MVC原理背道而驰吗?出于某种其他原因而变得愚蠢,例如表现?有什么优点吗?

Is this contrary to the MVC philosophy? Dumb for some other reason, like performance? Does it have any merit?

推荐答案

好的,为学习曲线画上另一个.我想我可能已经找到了自己的问题的答案...

OK, chalk up another for the learning curve. I think I might have found the answer to my own question...

ASP MVC允许您安装自己可以使用的自定义视图引擎(而不是默认的ASP.NET视图引擎).因此,您可以控制html的生成.一旦知道要搜索的内容,就很容易了:)

ASP MVC lets you install your own custom view engines which you can use (instead of the default ASP.NET view engine). So you can control the html generation. Once you know what to search for, its easy :)

这里是入门的好地方:自定义视图引擎示例

Here's a good place to get started: Custom View Engine Example

@Rajesh-感谢您的链接!

@Rajesh - Thanks for the great links!

这篇关于ASP.NET MVC视图-我可以使用代码隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆