开发者

ASp.NET MVC2 - Rendering an action link and text on same line

开发者 https://www.devze.com 2023-02-14 14:17 出处:网络
I will like to achieve the following html using Html.ActionLink: <li><a href=\"/WhatWeDo/JohnDoe\">John Doe</a>President</li>

I will like to achieve the following html using Html.ActionLink:

<li><a href="/WhatWeDo/JohnDoe">John Doe</a>President</li>

The name "John Doe" and title "President" will be coming from a staff model. This is what I have:

 <% foreach (var item in Model as IEnumerable<AkwiMemorial.Models.Staff>)
 { %>    
 <li><%= Html.ActionLink(item.Name, "GetStaffDetails", "WhatWeDo", new { staffID = item.Id }, n开发者_StackOverflow社区ull) %> item.Position</li>   
<% } %>

Instead of rendering "item.Position" literally, I will like this string extracted from the model.

TIA.


Try this:

<% foreach (var item in Model as IEnumerable<AkwiMemorial.Models.Staff>)
 { %>    
 <li>
    <%= Html.ActionLink(item.Name, "GetStaffDetails", "WhatWeDo", new { staffID = item.Id }, null) %> 
    <%=item.Position%>
 </li>   
<% } %>
0

精彩评论

暂无评论...
验证码 换一张
取 消