asp.net mvc - MVC Logic, Views and Helpers - A Specific Story -


me , colleague discussing how generate link on page. should use html helpers or keep simple view logic in view?

for project using castle monorail , nvelocity view engine. grateful considers both options below , gives opinions.

in story, link used on single page.

option 1 - helper

helper 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 in view, call helper so:

<li>$html.snailactivationswitchlink($item)</li> 

option 2 - in view

#if($snail.isactive)   <a href="$url.for("%{action='confirmdeactivate', querystring='id=$snail.id'}")">deactivate</a>   #else    <a href="$url.for("%{action='confirmactivate', querystring='id=$snail.id'}")">activate</a>   #end 

for me prefer option 1. more convenient logic on helper , more elegant.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -