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.

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


<%@ 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">

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


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

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

<% } %>


Open in new window

            <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>


Open in new window

Who is Participating?
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

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.