Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Johan 95 posts 264 karma points
    Dec 11, 2015 @ 13:11
    Johan
    0

    For each loop inside a href?

    I'm wondering if it's possible to put a foreach loop inside a href?

    The reason is because I want a link to be able to link to multiple emails and I don't know how to do it otherwise.

    I'm using HTML, Razor

    I tried doing like this:

     @foreach (var syv in syvs)
                {
                   <a href="mailto:@syv.ePost" target="_top">@syv.ePost</a>
    
                }
    

    But now it displays all the mails. What I want is one link that mails to all.

    I need something that only loops the mails inside the link, but I can't figure out how

    I appreciate any help

  • Dan Lister 416 posts 1974 karma points c-trib
    Dec 11, 2015 @ 13:29
    Dan Lister
    0

    Hi Johan,

    Something like the below may be something you'd want. The code below loops through every ePost and creates a string. Then one link is outputted containing all ePost email addresses.

    @{
        var href = string.Empty;
    
        foreach (var syv in syvs)
        {
            href = string.format("{0}, {1}", href, syv.ePost);
        }
    }
    
    <a href="mailto:@href">Send Email</a>
    

    Hope that helps.

    Thanks, Dan.

  • Johan 95 posts 264 karma points
    Dec 11, 2015 @ 13:43
    Johan
    0

    Thank you, Dan.

    How do I add a comma after each mail?

    I tried it @syv.ePost + ";" but it didn't work

  • Anders Bjerner 487 posts 2995 karma points MVP 8x admin c-trib
    Dec 11, 2015 @ 16:45
    Anders Bjerner
    0

    By using a bit of LINQ, you should be able to do it like:

    string href = String.Join(";", from syv in syvs select syv.ePost);
    
Please Sign in or register to post replies

Write your reply to:

Draft