I would like automapper to generate the url for the 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 EditUrl created using the routes defined for the application.
Something like that:
listIten.EditUrl = Url.Action("Edit", "UserController", new { id = user.Id });
There seems to be no way to get AutoMapper for this. There is no RequestContext, UrlHelper or anything available to display expressions, and I have not found a way to pass the context when calling Mapper.Map.
Am I missing something? Or is it just a bad idea to do this in the first place?
Update: additional background
Iām exploring alternative ways to generate URLs for MVC views in order to make ASP.NET MVC application maintenance as easy as possible. Creating URLs when mapping viewmodels is one alternative. Easy to check and clear presentation. In some cases, this would also facilitate reuse. Having tried this idea, I came across a brick wall when AutoMapper was unable to accept any (dynamic) context for the Map operation.
source share