ASP.NET MVC传递一个ID在ActionLink的到控制器 [英] ASP.NET MVC passing an ID in an ActionLink to the controller

查看:306
本文介绍了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)%>

这篇关于ASP.NET MVC传递一个ID在ActionLink的到控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆