문제

I'm working through the NerdDinner MVC tutorial and came across this and was wondering about.

On page 62 of the pdf they have the following:

<asp:Content ID="Main" ContentPlaceHolderID="MainContent" runat="server">
    <h2>Upcoming Dinners</h2>
    <ul>
        <% foreach (var dinner in Model) { %>
            <li>
                <a href="/Dinners/Details/<%=dinner.DinnerID %>">
                    <%= Html.Encode(dinner.Title) %>
                </a>
                on
                <%= Html.Encode(dinner.EventDate.ToShortDateString())%>
                @
                <%= Html.Encode(dinner.EventDate.ToShortTimeString())%>
            </li>
        <% } %>
    </ul>
</asp:Content>

They then state that instead of using an <a> tag that you can use the Html helper like so:

<%= Html.ActionLink(dinner.Title, "Details", new { id=dinner.DinnerID }) %> 

The question is: Isn't it still important to Html.Encode the dinner.Title from the Model when using this approach? If not, why not? If so, is there a way to use the Html.ActionLink and still use Html.Encode?

도움이 되었습니까?

해결책

Html.ActionLink already calls Encode, internally (see the source). You don't want to do it twice.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top