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");
        }

This is my Action has been defined in ABCControllers and want to access this action by using url www.urlname/ABC/12 but it is not accessible. I have used concept of routing in mvc3. Please help me

Answers


You can try the following route,

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

Try this, create an action Link:

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

If this not work then create another action and use RedirectToAction to go into Index action


Need Your Help

Beans are not getting autowired

spring-mvc autowired

I am creating simple spring MVC with hibernate project and I am using autowiring concept in my code. But on running my application I am getting the following exception.

Error in installing windows printer driver

windows printing driver device-driver

I am trying to install a windows printer driver(OEMUNI) provided as a sample in WDK(Windows Driver Kit). But I keep getting following error from add printer wizard: "Printer driver was not installed.