I have a class library that sends out emails for various events in my application. part of the email is a link to get back to the affected area of the site.
Is there the equivalent to Url.Action() for a class library to generate the link?
I have a class library that sends out emails for various events in my application. part of the email is a link to get back to the affected area of the site.
Is there the equivalent to Url.Action() for a class library to generate the link?
Assuming that the email is generated by somewhere in your MVC site, you could always pass through the Url from the controller into your class library in order to create the url there...
Your controller
public ActionResult SendOutEmail()
{
MyClass myClass = new MyClass();
CreateMyEmail(Url, myClass);
return View();
}
Your library class here...
public static void CreateMyEmail(UrlHelper url, MyClass informationToSend)
{
string myUrl = url.Action(...);
//and the rest of your class...
}
var requestContext = ControllerContext.RequestContext;
var routeData = ControllerContext.RouteData;
...
var path = routeData.Route.GetVirtualPath(requestContext, routeData.Values).VirtualPath;