繁体   English   中英

如何在mvc3中调用参数化的索引操作?

[英]How to call parameterized Index Action in mvc3?

public ActionResult Index(int id)
        {
            List<tablename> lListsong = new List<tablename>();
            using (dbname dbcontext=new dbname ())
            {
                lListsong = (from z in dbcontext.tablenamewhere z.SongId ==id select z).ToList();
            }
            foreach (var Songchooesen in lListsong)
            {
                ViewBag.selectedsong = Songchooesen.SongName.ToString();
            }
            return View("Index");
        }

这是我的行动已在ABCControllers中定义,并希望通过使用URL www.urlname / ABC / 12来访问此操作,但它无法访问。 我在mvc3中使用了路由的概念。 请帮我

试试这个,创建一个动作链接:

@Html.ActionLink("Add Related Data","Index",new { @id=12})

如果这不起作用,则创建另一个操作并使用RedirectToAction进入Index操作

您可以尝试以下route

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

暂无
暂无

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

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