1

这是我用来创建顶级链接的代码:

@Html.ActionLink("Edit",Url.Action("Edit","Home", new{row.Application_ID})) 
// supposed to return /Home/Edit/x (application_id)

相反,它返回: /Home/Home /Edit/x // 当前视图是 Home/Edit

请帮忙。

编辑 1: 路由表信息:

//This is for Edit 
routes.MapRoute(
           "Edit", // Route name
           "Home/Edit/{application_id}", // URL with parameters
           new { controller = "Home", action = "Edit", application_id = UrlParameter.Optional } // Parameter defaults
        );

        // This is the default route, I've modified it to LogOn.
        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Account", action = "LogOn", id = UrlParameter.Optional } // Parameter defaults
        );
4

3 回答 3

0

你不需要 inner @Url.Action,试试这个:

@Html.ActionLink("Edit", "Edit", "Home", new { application_id  = row.Application_ID }, null);
于 2013-10-03T09:04:59.123 回答
0

作为haim770回答的小版。如果你出于某种原因想要使用Url.ActionHtml.ActionLink你总是可以这样写:

<a href="@Url.Action("Edit", "Home", new { application_id  = row.Application_ID })">Edit</a>

一些开发人员更喜欢这种方式,因为它更类似于普通 Html,但结果与 Html.ActionLink 相同

于 2013-10-03T09:52:35.647 回答
0

尝试了这项工作,它奏效了:

<a href="..@Url.Action("Edit",new{application_id})">Edit</a>

现在它将链接返回为Home/Edit/x :)

于 2013-10-03T10:13:00.040 回答