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

  • Home
  • SEARCH
  • 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 8081473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:44:20+00:00 2026-06-05T16:44:20+00:00

I am trying to convert the popular asp.net MVC 2.0 solr.net sample app code

  • 0

I am trying to convert the popular asp.net MVC 2.0 solr.net sample app code to Razor syntax. I am not able to understand the last line … Kindly help

 <% Html.Repeat(new[] { 5, 10, 20 }, ps => { %>
            <% if (ps == Model.Search.PageSize) { %>
            <span><%= ps%></span>
            <% } else { %>
            <a href="@Url.SetParameters(new {pagesize = ps, page = 1})">@ps</a>
            <% } %>
  <% }, () => { %> | <% }); %>

[update]
Source for Html.Repeat extension

HtmlHelperRepeatExtensions.cs

  • 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-06-05T16:44:21+00:00Added an answer on June 5, 2026 at 4:44 pm

    For this to work you will have to modify the Html.Repeat extension method to take advantage of Templated Razor Delegates as illustrated by Phil Haack. And then:

    @{Html.Repeat(
        new[] { 5, 10, 20 }, 
        @<text>
            @if (item == Model.Search.PageSize)
            {
                <span>@item</span>
            }
            else
            {
                <a href="@Url.SetParameters(new { pagesize = item, page = 1 })">
                    @item
                </a>
            }
        </text>,
        @<text>|</text>
    );}
    

    UPDATE:

    According to your updated question you seem to be using a custom HTML helper but as I stated in my answer you need to updated this helper to use the Templated Razor Delegates syntax if you want it to work. Here’s for example how it might look:

    public static class HtmlHelperRepeatExtensions
    {
        public static void Repeat<T>(
            this HtmlHelper html,
            IEnumerable<T> items,
            Func<T, HelperResult> render,
            Func<dynamic, HelperResult> separator
        )
        {
            bool first = true;
            foreach (var item in items)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    separator(item).WriteTo(html.ViewContext.Writer);
                }
    
                render(item).WriteTo(html.ViewContext.Writer);
            }
        }
    }
    

    or if you want to have the helper method directly return a HelperResult so that you don’t need to use the brackets when calling it:

    public static class HtmlHelperRepeatExtensions
    {
        public static HelperResult Repeat<T>(
            this HtmlHelper html,
            IEnumerable<T> items,
            Func<T, HelperResult> render,
            Func<dynamic, HelperResult> separator
        )
        {
            return new HelperResult(writer =>
            {
                bool first = true;
                foreach (var item in items)
                {
                    if (first)
                        first = false;
                    else
                        separator(item).WriteTo(writer);
                    render(item).WriteTo(writer);
                }
            });
        }
    }
    

    and then inside your view:

    @Html.Repeat(
        new[] { 5, 10, 20 }, 
        @<text>
            @if (item == Model.Search.PageSize)
            {
                <span>@item</span>
            }
            else
            {
                <a href="@Url.SetParameters(new { pagesize = item, page = 1 })">
                    @item
                </a>
            }
        </text>,
        @<text>|</text>
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to convert an ASP.NET website into a web application project. The
Trying to convert this c code into MIPS and run it in SPIM. int
Im trying to convert some Delphi code to c# and I've come across a
Trying to convert a string to NSURL and this is not happening. barcodeTextLabel.text =
Trying to convert a two dimensional array to a two dimensional JSON.Net array. Is
Trying to convert some VB to C#... (learning C#, too). I have some code
i'm trying to convert the following code from Java to C#. // Replace 0
I'm trying to convert old QuickTime framework code to the 64-bit Cocoa-based QTKit on
I'm trying to convert some code that worked great in VB, but I can't
I have a code in vb, and I'm trying convert it to c#. _nextContactDate.ToShortDateString

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.