Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6351215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:57:34+00:00 2026-05-24T21:57:34+00:00

I have a simple foreach template and inside every element I want an ActionLink

  • 0

I have a simple foreach template and inside every element I want an ActionLink but that ActionLink needs to send an Id to edit the element.

The item to be templated:

<div data-bind="template: {
                    name: 'postsTemplate',
                    foreach: posts
                    }">
</div>

The template:

<script id="postsTemplate" type="text/html">
<h2 data-bind="text: Title"></h2>

<p class="post-info">
    <p class="post-info" data-bind="text UserName"></p>
    <span data-bind="Body"></span>
    <p class="post-footer">
        @Html.ActionLink("Comments", "IndividualPost", "Post", null, null, "comments", new {id = })
    </p>
</p>
</script>

How can I send the actual post Id through the ActionLink? I mean, How I can access to the post’s id without using data-bind? (Because it’s a helper).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T21:57:36+00:00Added an answer on May 24, 2026 at 9:57 pm

    If you would implement your own ActionLink extension along the line of:

    public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText,
                                           string actionName, string controllerName,
                                           object routeValues,  bool noEncode)
        {
            var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);
            var url = urlHelper.Action(actionName, controllerName, routeValues);
    
            if (noEncode) url = Uri.UnescapeDataString(url);
    
            var tagBuilder = new TagBuilder("a");
    
            tagBuilder.MergeAttribute("href", url);
            tagBuilder.InnerHtml = linkText;
    
            return MvcHtmlString.Create(tagBuilder.ToString(TagRenderMode.Normal));
        }
    

    Then you could make your template like:

    <p class="post-info">
        <p class="post-info" data-bind="text UserName"></p>
        <span data-bind="Body"></span>
        <p class="post-footer">
            @Html.ActionLink("Comments (${CommentCount})", "IndividualPost", "Post", 
                             new {id = "${id}"}, true)
        </p>
    </p>
    

    the serverside html generated would then look like:

    <p class="post-info">
        <p class="post-info" data-bind="text UserName"></p>
        <span data-bind="Body"></span>
        <p class="post-footer">
           <a href="/Post/IndividualPost/${id}">Comments (${CommentCount})</a>
        </p>
    </p>
    

    which in turn is a perfect template in my opinion.

    The reason for an ActionLink extension is the fact that the normal Html.ActionLink encodes your url to /Post/IndividualPost/%24%7Bid%7D which doesn’t work for the template

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a pretty simple case which I started solving using foreach(), but then
I have a very simple query $this->db->select('id, title'); $this->db->order_by('id', 'DESC'); $query = $this->db->get('journal'); foreach($query->result()
I have simple win service, that executes few tasks periodically. How should I pass
I'm building a simple NVelocity template but I can't figure out how to test
I noticed a strange behavior in Knockout's template rendering. I have a simple Knockout
I have a fairly simple model that uses Django Taggit for tagging. Everything works
I have created a Word template that I am then processing via the OpenXML
I have created a simple WordPress page template. I am working on live server.
I have a simple table of languages / template id's: language | template en,
I have simple regex \.*\ for me its says select everything between and ,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.