0

I am working on ASP.NET MVC3. I have a partial view RestaurantAdminNavigation.ascx which i moved from Views/Restaurant Folder to Views/Shared Folder.

I have a action link in that view

<%:Html.ActionLink("Edit", "Edit", "Restaurant", new { id=Model.OId }) %>

It was working fine when it was at Views/Restaurant folder but after moving at Views/Shared folder, if I keep the parameters as a part of that action link, it shows me an error 'Can not resolve action edit'. But if i keep

<%:Html.ActionLink("Edit", "Edit", "Restaurant") %>

it does not show me error.

After Googling i understand the reason might be registering the routes. I need to register route in Global.ascx file but i can not understand what might should I code if this is the solution.

Foyzul Karim
  • 4,252
  • 5
  • 47
  • 70
  • Can you provide the code in your RestaurantController's Edit action? – Suhas Nov 02 '11 at 04:56
  • By the looks of it, it should work without issues. Do you have any attributes applied to this action? Do you have another overload of Edit action in that controller? – Suhas Nov 02 '11 at 05:03
  • no overload except the HTTP Post. – Foyzul Karim Nov 02 '11 at 05:27
  • The ActioLink by default generates a GET request so HTTP Post actions would not work here. What amazes me though is, how it works without Id parameter. I'm still feeling there is an Edit action which does not accept id parameter – Suhas Nov 02 '11 at 06:11
  • Hi. thanks for your responses. now it is taking the URL as http://localhost/mysite/Restaurant/Edit?Length=10 – Foyzul Karim Nov 02 '11 at 06:23
  • For your kind info OId (String) is 10 character in length. if i see the source of the html it is displaying Edit – Foyzul Karim Nov 02 '11 at 06:26
  • i guess it is happening because of map routing in Global.ascx file. – Foyzul Karim Nov 02 '11 at 06:27

1 Answers1

5

You are using a wrong overload of the ActionLink helper:

<%= Html.ActionLink(
    "Edit",                  // linkText
    "Edit",                  // actionName
    "Restaurant",            // routeValues
    new { id = Model.OId }   // htmlAttributes
) %>

And here's the correct one:

<%= Html.ActionLink(
    "Edit",                  // linkText
    "Edit",                  // actionName
    "Restaurant",            // controllerName
    new { id = Model.OId },  // routeValues
    null                     // htmlAttributes
) %>
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928