Domanda

This is my code that i'm using to create a link to top level link:

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

Instead, it returns: /Home/Home/Edit/x // Current View is Home/Edit

Please help.

Edit 1: Route Table information:

//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
        );
È stato utile?

Soluzione

As a small edition to haim770 answer. if you want for some reason use Url.Action instead Html.ActionLink you are always free to write it like that:

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

Some developers prefere this way because it more similar to plain Html, but result is the same as Html.ActionLink

Altri suggerimenti

You don't need the inner @Url.Action, try this instead:

@Html.ActionLink("Edit", "Edit", "Home", new { application_id  = row.Application_ID }, null);

tried this work around and it worked:

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

now it returns the link as Home/Edit/x :)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top