ASP.NET MVC传递一个ID在ActionLink的到控制器

ASP.NET MVC传递一个ID在ActionLink的到控制器

问题描述:

我看不到检索一个ID,我在我的控制器发送一个html.ActionLink,这里是我正在试图做的。

I can't see to retrieve an ID I'm sending in a html.ActionLink in my controller, here is what I'm trying to do

<li>
    <%= Html.ActionLink("Modify Villa", "Modify", "Villa", new { @id = "1" })%></li>


    public ActionResult Modify(string ID)
    {

        ViewData["Title"] =ID;
        return View();
    }

这就是我跟着什么建议的教程,但它不工作,它也把?长度= 5在网址的结尾!

That's what a tutorial I followed recommended, but it's not working, it's also putting ?Length=5 at the end of the URL!

在此先感谢!

编辑:这里是我使用的路线,它的默认

edit: here is the route I'm using, it's default

        routes.MapRoute(
            "Default",                                              // Route name
            "{controller}/{action}/{id}",                           // URL with parameters
            new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
        );

似乎有人downvoted以下两个建议,但没有公布他们的解决方案!

it appears someone has downvoted the two suggestions below but not posted their solution!

看起来不像你正在使用ActionLink的正确的过载。试试这个: -

Doesn't look like you are using the correct overload of ActionLink. Try this:-

<%=Html.ActionLink("Modify Villa", "Modify", new {id = "1"})%>

这假定您的观点是/查看/别墅文件夹下。如果没有,那么我怀疑你需要: -

This assumes your view is under the /Views/Villa folder. If not then I suspect you need:-

<%=Html.ActionLink("Modify Villa", "Modify", "Villa", new {id = "1"}, null)%>