views:

57

answers:

1

In my view the call below generates url ending with Tasks/Edit but I want it to generate url like Tasks/Edit/23

<%= Html.ActionLink<TaskController>("Edit Task", (x) => x.Edit("23"))%>

in Global.asax:

string taskController = NameResolver.NameOfController<TaskController>();
string editAction = NameResolver.NameOfAction<TaskController>(x => x.Edit(null));
routes.MapRoute(
       "EditTasks",
       "Tasks/Edit/{id}",
       new { controller = taskController, action = editAction, id = string.Empty });

I also have binding problem in this action. Values set from view is not binded to my Edit parameter. It comes null everytime and I have not set DefaultModelBinder anywhere. Here is the Edit action:

    public ActionResult Edit (string id)
    {
       //retrieve some data and pass it to view and return view
    }

So what can be the problem here? How can I solve url and binding problem? And yes I am a Asp.Net Mvc beginner :)

+3  A: 
<%= Html.ActionLink("Task", "Edit", new { id = "2" }) %>

Although why is your id a string and not an int?

Yuriy Faktorovich
Thanks a lot. For id thing it is not actually an integer, for simplicity I changed it this way in code sample. One more question: Can I use strongly typed action name, ie not "Edit", does Mvc has such utility?
arch stanton
@arch stanton: I can't see how you can use a strongly typed action name because Edit is a method not a class without some serious screwing around by parsing LINQ expressions. I'll give this a shot when I have time, but even if possible, it should never make it to production. It would be a bad hack that is not maintainable.
Yuriy Faktorovich
I heard MvcContrib supports those strongly typed usages like Html.ActionLink<TaskController>("Edit Task", (x) => x.Edit("23")). But not tried it myself.
arch stanton