Trying to figure out what makes more sense
<%foreach (var item in Model.items) { %> <tr> <td> <% if (!item.isMgmt) { %> <a href="/MVC/AzureMail/Unfiled/<%:item.uName %>"> <%:item.uName%></a> <% } else { %> <%:item.uName %> <% } %> </td> </tr> <% } %>
or
<%foreach (var item in Model.items) { %> <tr> <td> <% if (!item.isMgmt) { %> <a href="/MVC/AzureMail/Unfiled/<%:item.uName %>"> <% } %> <%:item.uName%> <% if (!item.isMgmt) { %> </a> <% } %> </td> </tr> <% } %>
third option; extension method for conditional link.
public static string ConditionalHyperlink(this HtmlHelper helper, string url, string text, bool shouldLink){ ... }
This greatly simplifies viewing.
<%= Html.ConditionalHyperlink("/MVC/AzureMail/Unfiled/" + item.Name, item.Name, item.isMgmt) %>
First option. It seems more logical to have all the associated logic that creates the link in the expression, and not in the split in option 2.
Edit: I think most agree that option 1 is better. I am a supporter of HtmlHelpers (= cleaner views), so my additional suggestion was that you create an assistant that wraps the logic you represent.
, , , . .
, , href . , # 2.
,
, , . , . , , , RenderName, HREF, isMgmt true , . , , :
<%foreach (var item in Model.items) { %> <tr> <td> <%:item.RenderName %> </td> </tr> <% } %>
, , .
<%foreach (var item in Model.items) { %> <tr> <td> <%: item.isMgmt ? item.uName : string.format("<a href=\"/MVC/AzureMail/Unfiled/{0}\"">{0}</a>, item.uName) %> </td> </tr> <% } %>
html-
Source: https://habr.com/ru/post/1756567/More articles:Is there any security benefit when using a stored procedure to toggle a boolean value from a flag - c #What formal language class are XML and JSON with unique keys (they are not contextual) - jsonInsert java applet in Wordpress - javaAppFabric caching error: AppFabric caching service terminated unexpectedly - windows-servicesGrails json string converter with dates - grailsMySQL performance, internal join, how to avoid using temporary and fileort - performanceAnimated Animation for Android - androiddriver compilation - android-ndkCan sql multi query be considered as atomic instruction? - php"PHP-ext" -like PHP widget libraries? - phpAll Articles