繁体   English   中英

我在asp.net-mvc中在做什么错呢?

[英]What am i doing wrong with this in asp.net-mvc?

我在我的site.master

<li><%= Html.ActionLink("Material", "Index", "Material")%></li>

但是我的链接似乎没有得到我的material控制器Index方法...我在全局asax文件中有此方法,

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default",                                              
                "{controller}/{action}/{id}",                           
                new { controller = "Home", action = "Index", id = "" }  
             );

            routes.MapRoute(
                "Default",                                              
                "{controller}/{action}/{id}",                            
                new { controller = "Material", action = "Index", id = "" }  
            );

        }

我的控制器:

public class MaterialController : Controller
{
    //
    // GET: /Material/
    Material material = new Material();
    public ActionResult Index()
    {
        var materials = material.FindAllMaterials();
        return View();
    }
 }

我在做什么错...。当我单击链接时,我得到The resource cannot be found. 错误..任何建议...

您的意思是“但是我的链接似乎没有得到我的物料控制者”? 它生成的链接是什么?

从此处下载路由调试器: http : //haacked.com/archive/2008/03/13/url-routing-debugger.aspx

注册它,并查看在您手动输入url时使用的路由。

转储问题->确保已保存/编译。 暗示您未执行此操作的原因是,您有两条具有相同名称的路由(也称为默认路由)。 编译器应该出错。

其次,尝试手动转到该资源。 即,转到http:// localhost :/ materials / index,看看是否可行。 当然,用您网站的开发URL替换localhost。 如果可行..继续。

第三,将鼠标悬停在html锚点(又名a href)上,然后查看浏览器“状态”栏中显示的内容。 它应该列出该锚定将您重定向到的资源URL。 它说' http:// localhost :/ materials / index'吗?

基本上,HTML.ActionLink ..的代码看起来还不错,但是发生了一些其他可能的事情,使问题更加复杂。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM