MVC 获取控件查看 HTML 值
我很好奇是否有可能从控制器(或其他地方)获取控制视图的实例,将其所需的模型传递给它并获取它将输出的 html?
例如,我有一个构建排行榜的控制视图。这对于在网站上使用它时很好,但我也想将此排行榜放入我发送的 html 电子邮件中...我可以使用控制视图来执行此操作还是必须重新创建排行榜?
I was curious to see if its possible that from a controller (or else where) could I get a instance of a Control View pass it the model it requires and get back the html that it would output?
For example I have a Control View that builds a league table. This is fine for when using it on the site but I also want to put this league table into a html email that I send out... can I use the control view to do this or do I have to recreate the league table?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果将表本身放入分部视图中,则可以轻松使用 Html.RenderPartial() 来获取其输出。如果您拥有一个从数据存储中获取适当数据并返回部分数据的操作方法,您甚至可以使用 Html.Action()(假设您使用 MVC2 或更高版本)。
If you put the table itself in a partial view, you could easily use
Html.RenderPartial()
to get the output from it. If you go so far as having an action method that gets the appropriate data from your data store and returns the partial, you could even useHtml.Action()
(given that you use MVC2 or higher).