Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 3 如何通过操作按项目组名获取项目列表?_Asp.net Mvc 3 - Fatal编程技术网

Asp.net mvc 3 如何通过操作按项目组名获取项目列表?

Asp.net mvc 3 如何通过操作按项目组名获取项目列表?,asp.net-mvc-3,Asp.net Mvc 3,我的布局显示了组合列表中的菜单,当我单击其中一个菜单项时,它应该转到显示此组合中所有主题的页面,但当我这样做时,出现以下错误: Server Error in '/' Application. The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been remove

我的布局显示了组合列表中的菜单,当我单击其中一个菜单项时,它应该转到显示此组合中所有主题的页面,但当我这样做时,出现以下错误:

    Server Error in '/' Application.
    The resource cannot be found.
    Description: HTTP 404. The resource you are looking for (or one of its
    dependencies) could have been removed, had its name changed, or is 
    temporarilyunavailable.  
    Please review the following URL and make sure that it is spelled correctly.

    Requested URL: /Home/Browse/1

    Version Information: Microsoft .NET Framework Version:4.0.30319;
    ASP.NET Version:4.0.30319.225 
我有“ThemeModel.cs”可以提供主题的属性,有“ThemeGroupsModel.cs”可以提供“id”和“ThemeGroupName”,在我的项目中有一个名为“Services”的文件夹,该文件夹的类为“ThemeSrv.cs”。 此类有一个具有以下代码的方法:

   public List<ThemesModel> getAllTheme(short ThemeGrId)
    {
   List<ThemesModel> ThemeList = new List<ThemesModel>();
        ThemesModel themeTemp;
        using (var context = new EShopThemeDBEntities(idbconnection.ConnStr))
        {
            var ThemesDb = (from o in context.Themes
                            where o.ThemeGroupId == ThemeGrId
                            select o).ToList();
            if (ThemesDb != null)
            {
                foreach (var item in ThemesDb)
                {
                    themeTemp = new ThemesModel();

                    themeTemp.ThemeID = item.ThemeID;
                    themeTemp.ThemeName = item.CodeName;
                    themeTemp.HtmlF = item.Html;
                    themeTemp.JoomlaF = item.Joomla;
                    themeTemp.Image = item.Image;
                    themeTemp.PsdF = item.PSD;
                    themeTemp.UploadDate = item.UploadDate;
                    themeTemp.UnitPrice = (float)item.UnitPrice;
                    ThemeList.Add(themeTemp);
                }
            }
        }
        return ThemeList;
    }
这些代码位于我的“\u LayoutMain.cshtml”中,用于在我的所有页面中显示菜单:

   @{EshopTheme.Models.HomeModel hm = new EshopTheme.Models.HomeModel();     
   }
     <ul id="menu">
                @foreach (var item in hm.ThemeGr)
                {

                    <li>
                    @Html.ActionLink(item.ThemeGroupName, "Browse", "Home", 
                    new { id = item.ThemeGroupId }, new { @class = "linkMenu" })

                    </li>
                } </ul>
@{EshopTheme.Models.HomeModel hm=新的EshopTheme.Models.HomeModel();
}
    @foreach(hm.ThemeGr中的var项目) {
  • @ActionLink(item.ThemeGroupName,“浏览”,“主页”, 新建{id=item.ThemeGroupId},新建{@class=“linkMenu”})
  • }
我为名为“Brows.cshtml”的“Browse”操作创建视图,以显示结果。当我单击菜单中的一个项目(像“sport”这样的主题组之一)时,它会显示名为“sport”的所有主题的列表

@{EshopTheme.Models.HomeModel hm=新的EshopTheme.Models.HomeModel();
ViewBag.Title=“浏览”;
Layout=“~/Views/Shared/\u LayoutMain.cshtml”;
}
    @foreach(hm.ThemesByGrIds中的var项) {
  • }

我有什么问题??
感谢您的帮助……

您很可能会收到404,因为您的路由配置错误和/或您正试图
获得
发布
操作结果。试试这个

路线

routes.MapRoute(
      name: "Browse",
      url: "{controller}/{action}/{themeGroupId}",
      defaults: new { controller = "Home", action = "Index", themeGroupId = UrlParameter.Optional }
);
行动结果

public ActionResult Browse(short themeGroupId)
{
    var themes = new ThemeSrv();
    return View(themes.getAllTheme(themeGroupId));
}

您需要告诉路由引擎有关要传递给
操作结果的参数

浏览(短ThemeGroupId)-将其更改为->浏览(int ThemeGroupId)可能工作浏览(短ThemeGroupId)-将其更改为->浏览(int id)工作感谢大家。。。你的帮助解决了我的问题。我删除了“浏览”操作之前的[httpPost],并将“浏览(短ThemeGroupId)”更改为“浏览(int id)”。。。
   @{ EshopTheme.Models.HomeModel hm = new EshopTheme.Models.HomeModel();

ViewBag.Title = "Browse";
Layout = "~/Views/Shared/_LayoutMain.cshtml";
   }


   <ul id="themeList">

@foreach (var item in hm.ThemesByGrIds )
{
    <li><a href="@Html.ActionLink(item.ThemeName, "Browse", "home",
 new { id=item.ThemeID })">
        <img src="@item.Image" alt="@item.ThemeName" /><br />
        <span>Theme Name: @item.ThemeName </span>
        <br /><span>Upload date: @item.UploadDate
        </span>
    @*  <span>price: @item.UnitPrice</span>*@
         </a></li>

}
routes.MapRoute(
      name: "Browse",
      url: "{controller}/{action}/{themeGroupId}",
      defaults: new { controller = "Home", action = "Index", themeGroupId = UrlParameter.Optional }
);
public ActionResult Browse(short themeGroupId)
{
    var themes = new ThemeSrv();
    return View(themes.getAllTheme(themeGroupId));
}