2012-09-14 20 views
-1

我有一个显示来自ThemeGroups列表菜单中,当我点击的菜单项目之一的布局,就应该到页面,显示在此ThemeGroup所有主题的,但是当我做到这一点,出现此错误:我怎样才能得到他们的groupName与行动的项目列表?

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

我有了这些属性HomeModel:

using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Web; 
    using EshopTheme.Services; 

    namespace EshopTheme.Models 
    { 
public class HomeModel 
{ 
    public MenuSrv MenuList { get; set; } 
    public IEnumerable<ThemeGroupsModel> ThemeGr { get; private set; } 

    public ThemeSrv ThemesByGrId { get; set; } 
    public IEnumerable<ThemesModel> AllThemes { get; private set; } 

    public HomeModel() 
    { 
     this.MenuList = new MenuSrv(); 
     this.ThemeGr = this.MenuList.getAllThemeGroup(); 

     this.ThemesByGrId = new ThemeSrv(); 
     this.AllThemes = ThemesByGrId.getAllTheme(2); 
    } 

这是我在HomeController的行动:

[HttpPost] 
    public ActionResult Browse(short ThemeGroupId) 
    { 
     var themes = new ThemeSrv(); 

     return View(themes.getAllTheme(ThemeGroupId)); 
    } 

和这些代码在我的“_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> 

我创建名称为“Brows.cshtml”“浏览”行动,以显示结果时,我在一个项目中的菜单(专题组,如“运动”的一个),单击视图,它显示了所有的主题列表与名称组“运动”。

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

} 

什么是我的问题? 感谢您的帮助...

+0

浏览参数路由引擎(短ThemeGroupId ) - 将其更改为 - > Browse(int ThemeGroupId)ma它工作 – motevalizadeh

+0

浏览(简短ThemeGroupId) - 改为 - >浏览(INT ID)它的工作 – motevalizadeh

回答

0

您最有可能得到404,因为您的路由配置错误和/或您尝试GET a POST操作结果。试试这个

路线

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

的ActionResult

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

你需要告诉你想要传递给ActionResult

+0

谢谢所有... 我的问题已经解决了你的帮助。 我删除了我的“Brows”动作之前的[httpPost],并将“Browse(short ThemeGroupId)”更改为“Browse(int id)”... – Smo

相关问题