I would like automapper to generate URL's for a view model. For example, this is my data object:
public class User
{
public int Id { get; set; }
public int Name { get; set; }
}
The view model looks something like this:
public class UserListItem
{
public string Name { get; set; }
public string EditUrl { get; set; }
}
I would like the EditUrl
property to be generated using the routes defined for the application.
Something like this:
listIten.EditUrl = Url.Action("Edit", "UserController", new { id = user.Id });
There seems to be no way to get AutoMapper to do this. There is no RequestContext, UrlHelper or anything available for mapping expressions and I haven't found any way to pass in context when invoking Mapper.Map.
Am I missing something? Or is it just a bad idea to want to do this in the first place?
Update: Additional background
I'm investigating alternative ways of generating URLs for MVC views with the aim of making ASP.NET MVC application maintenance as easy as possible. Generating URLs while mapping the viewmodels is one of the alternatives. It's easy to test and cleans up the view. It would also promote view re-usability in some cases. While trying out this idea I ran into a brick wall with AutoMapper not being able to accept any kind of (dynamic) context for a Map
operation.