My colleague and I discuss how we will create the link on the page. Should we use html helpers or adhere to very simple presentation logic in the view?
For this project we use Castle Monorail and the NVelocity view engine. I would be grateful to everyone who will consider both options below and express their opinion.
In this story, the link is currently only used on one page.
Option 1 - with an assistant
Assistant Code
var action = snail.IsActive ? "ConfirmDeactivate" : "ConfirmActivate";
var routeValues = new Dictionary<string, string>
{
{"action", action},
{"querystring", "id=" + snail.ID}
};
var href = UrlHelper.For(routeValues);
var link = new XElement("a");
link.SetAttributeValue("href", href);
link.SetValue(action.Substring(7));
return link.ToString();
And then in the view, we simply call the helper as follows:
<li>$Html.SnailActivationSwitchLink($item)</li>
Option 2 - Everything in View
<a href="$Url.For("%{action='ConfirmDeactivate', querystring='id=$snail.ID'}")">Deactivate</a>
<a href="$Url.For("%{action='ConfirmActivate', querystring='id=$snail.ID'}")">Activate</a>
source
share