why i can not access new product List from MVC?

Hi! i try to learn Asp.net MVC.i created a sample application to learn it. But press f5 return server error. Where do l make a mistake? where is the problem? there is a navigator bar Home/About/Product . if i press Product, error return to me.

 Cotroller:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication1.Models.Db;

namespace MvcApplication1.Controllers
{
    public class ProductsController : Controller
    {
        //
        // GET: /Products/

        public ActionResult GetAll()
        {
            using (var ctx = new MyDbEntities())
            {
                ViewData["Products"] = ctx.Products;
                return View();
            }

        }

    }
}

Open in new window

View:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcApplication1.Models.Db.Product>" %>
<%@ Import Namespace="MvcApplication1.Models.Db" %>
<%@ Import Namespace="MvcApplication1.Controllers" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    ProductDetail
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <h2>ProductDetail</h2>
    <ul>

<% foreach (var m in (IEnumerable<Products>)ViewData["Products"])
     { %>

     <li><%= m.ProductName %></li>

<% } %>
</ul>

</asp:Content>

Open in new window

site.Master:
            <div id="menucontainer">

                <ul id="menu">              
                    <li><%: Html.ActionLink("Home", "Index", "Home")%></li>
                    <li><%: Html.ActionLink("About", "About", "Home")%></li>
                     <li><%: Html.ActionLink("Product", "ProductDetail", "Product")%></li>
                </ul>

            </div>

Open in new window

mvcsolutions.png
programmeristAsked:
Who is Participating?
 
binaryevoCommented:
That is because your link contains the wrong action.  Either add an action to your controller to match the action your asking for on your view HTML.ActionLink or adjust the actionlink to match your controller action.  If you modified your view it would you HTML.ActionLink would look like this:

<li><%: Html.ActionLink("Product", "GetAll", "Product")%></li>

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.