Git Product home page Git Product logo

Comments (4)

ajaybhargavb avatar ajaybhargavb commented on July 22, 2024 1

Currently there is no way of doing this if you need all the routing behavior to go with it. Since you have your own logic of url generation, you can just write your own implementations of IUrlHelperFactory and IUrlHelper and add it to services. You will get no routing magic there. You'll need to put your logic in the Action method, something like,

public class CustomUrlHelper : IUrlHelper
{
    public string Action(UrlActionContext actionContext)
    {
        return $"{actionContext.Protocol}://{actionContext.Host}/{actionContext.Controller}/{actionContext.Action}";
    }
    .
    .
    .
}

And just add services.AddSingleton<IUrlHelperFactory, CustomUrlHelperFactory>(); in Program.cs

from entropy.

muratg avatar muratg commented on July 22, 2024

@Eilon Could you triage/assign?

from entropy.

ajaybhargavb avatar ajaybhargavb commented on July 22, 2024

@Bartmax, this is not a limitation. This is expected. This sample was added to demonstrate rendering a view to a string given a model. It does not involve any controllers or actions. This isn't meant for that. Both Url.Action() and AnchorTagHelper need actions and controllers to be present. So you can't use them here.

from entropy.

Bartmax avatar Bartmax commented on July 22, 2024

I understand, thanks for your explanation.

I'm using this to create email html from models. In the same project I do have controllers and actions, that's why I want to use something like <a asp-controller="Home" asp-action="Help">help</a> but I also need them to be absolute not relative; //domain.com/Help instead of /Help.

Is there any sample that shows how to make it work with controller/actions or any guidance on what must be done/added ?

currently I'm doing logic on the ViewModel to get the url, maybe that's a reasonable way to do it ?

from entropy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.