Click here to Skip to main content
15,895,084 members
Articles / Web Development / ASP.NET

Implementing ASP.NET MVC Views in three different ways

Rate me:
Please Sign up or sign in to vote.
4.86/5 (18 votes)
24 May 2012CPOL9 min read 199.5K   2.9K   63  
Three different approaches for implementing the View role in an MVC application.
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<IEnumerable<MVC_ASPX.Models.Product>>" %>

<!DOCTYPE html>

<html>
<head runat="server">
    <title>ProductView</title>
</head>
<body>
 <h2>Products List - ASPX View</h2>
    <p>
        <%: Html.ActionLink("Create New", "Create") %>
    </p>
    <table>
        <tr>
            <th></th>
            <th>
                ProductID
            </th>
            <th>
                ProductName
            </th>
            <th>
                Quantity
            </th>
            <th>
                Price
            </th>
        </tr>
    
    <% foreach (var item in Model) { %>
        <tr>
            <td>
                <%: Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) %> |
                <%: Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) %> |
                <%: Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ }) %>
            </td>
            <td>
                <%: item.ProductID %>
            </td>
            <td>
                <%: item.ProductName %>
            </td>
            <td>
                <%: item.Quantity %>
            </td>
            <td>
                <%: String.Format("{0:F}", item.Price) %>
            </td>
        </tr>  
    <% } %>
    
    </table>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions