是否可以从 ViewModel 返回 ActionLink html? (MVC3+剃刀)
我有四个视图模型/视图,它们显示相似但不同的数据。
是否可以在视图模型上设置一个属性来重新调整 ActionLinks(或它们的 html?)
例如 目前我对我的每一个观点都有
<table>
<tr>
<td>@Html.ActionLink("My Open Calls", "MyOpenCalls")</td>
<td>@Html.ActionLink("All Open Calls", "AllOpenCalls")</td>
<td>@Html.ActionLink("My Calls Today", "MyCallsToday")</td>
<td>@ViewBag.Title</td>
</tr>
</table>
,但是否有可能:
<table>
<tr>
@Model.MenuHtml
</tr>
</table>
I have a four viewmodels/views which display similar but different data.
Is it possible to have a property on the viewmodel which retuns ActionLinks (or the html for them ?)
e.g.
At the moment on each of my Views I have
<table>
<tr>
<td>@Html.ActionLink("My Open Calls", "MyOpenCalls")</td>
<td>@Html.ActionLink("All Open Calls", "AllOpenCalls")</td>
<td>@Html.ActionLink("My Calls Today", "MyCallsToday")</td>
<td>@ViewBag.Title</td>
</tr>
</table>
but would it be possible to have:
<table>
<tr>
@Model.MenuHtml
</tr>
</table>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然可以在视图模型属性中存储 HTML,但我认为这不是一个好主意。如果您想重用某些代码,为什么不简单地将此表放入部分表中,然后包含该部分:
另一种可能性是使用自定义 HTML 帮助程序来生成这些链接。
While it might be possible to store HTML in view models properties I don't think it would be a good idea. If you want to reuse some code why not simply put this table into a partial and then include the partial:
Another possibility is to use a custom HTML helper that will generate those links.