Reputation: 6091
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>
Upvotes: 0
Views: 351
Reputation: 1038820
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:
@Html.Partial("_Links")
Another possibility is to use a custom HTML helper that will generate those links.
Upvotes: 2