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 191667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:21:39+00:00 2026-05-11T16:21:39+00:00

I have a paging menu PartialView in my MVC app that looks like: <%

  • 0

I have a paging menu PartialView in my MVC app that looks like:

    <%  if (Model.TotalPages > 5) 
    {
        int index = Model.PageIndex;
        int minIndex = index - 2;
        int maxIndex = index + 2;
        if (index < 2) 
        { 
            minIndex = 0; 
            maxIndex = 4; 
        }
        if (index > Model.TotalPages - 2) 
        { 
            minIndex = Model.TotalPages - 5; 
            maxIndex = Model.TotalPages; 
        }
        for (int i = minIndex; i <= maxIndex; i++)
        { %>    
            <li>
                <span class="<%= Html.GetClass((i==index), "selected", "notselected") %>">
                    <a href="<%= Url.Action("TypeNav", "Catalog", new { controller = "Catalog", action = "TypeNav", group = Model.ProductGroup, position = 0, index = i, browseSize = 6 } ) %>" class="<%= Html.GetClass((i==index), "selected", "notselected") %>">
                        <%= i + 1%>
                    </a>
                </span>
            </li>
<%      } 
    } 
    else 
    {
        for(int i=0; i<Model.TotalPages; i++) { %>    
            <li>
                <span class="<%= Html.GetClass((i==Model.PageIndex), "selected", "notselected") %>">
                    <a href="<%= Url.Action("TypeNav", "Catalog", new { controller = "Catalog", action = "TypeNav", group = Model.ProductGroup, position = 0, index = i, browseSize = 6 } ) %> ">
                        <%= i+1 %>
                    </a>
                </span>
            </li>
<%      }
    } %>

What I cannot figure out is how to set a JQuery click event on the Anchor tags. Anchor tags do not have a NAME attribute and my (very) limited experience with JQuery is that it needs NAME attributes to work with.

Any pointers are quite welcome.

TIA

  • 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-11T16:21:40+00:00Added an answer on May 11, 2026 at 4:21 pm

    You can specify any CSS selector to get at your a tags and not just a name/ID. For example if you want all the anchor tags in your document to subscribe to your event something like

    $("a").click(function() { /* Do magic */ });
    

    would work. This does tend to mess up every other anchor tag on the page which might not be the effect you want either.

    If you want to give your a tags a common behaviour its sometimes just easier to give them a custom CSS class so you can hook up events via a more simple selector

    $(".pagerLink").click(function() { /* Do magic */ });
    

    If you don’t like the thought of that an alternative is to give the containing UL tag an ID then use a descendent selector

    $("#yourPager a").click(function() { /* Do magic */ });
    

    or looking at your markup a child selector might also be feasible

    $("span.selected > a, span.notselected > a")
          .click(function() {/* Do magic */ });
    

    i.e. Look for all a tags that are immediate descendents of span tags that either have the selected class or the not selected class.

    It’s worthwhile remembering you have to cancel the default behaviour of the a tag (e.g. navigating to your link) you can do this either by returning false from your event handler or using the jQuery event object and calling preventDefault

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

Sidebar

Related Questions

I have a paging UIScrollView that pages through multiple full screen images. I am
I have datagrid with paging enabled that can have 10 rows per page. Also
I'm trying to page a table, and while I have paging already working, it
Is it possible to using paging functionality in Linq queries? Let's say I have
I have a client that is paying $1500 per month for hosting of 1
Unobtrusive JS suggests that we don't have any onclick attributes in our HTML templates.
I have a Gridview, which is bound to an IList. I'd like to have
I have a jqGrid in an ASP.NET MVC View with the option multiselect:true .
I have a Paging UIScrollView with a contentSize large enough to hold a number
A follow on from the question I asked yesterday. I have a paging scrollView

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.