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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:04:50+00:00 2026-05-16T11:04:50+00:00

I have created an extension method for an ASP.NET MVC ViewPage, e.g: public static

  • 0

I have created an extension method for an ASP.NET MVC ViewPage, e.g:

public static class ViewExtensions
{
    public static string Method<T>(this ViewPage<T> page) where T : class
    {
        return "something";
    }
}

When calling this method from a View (deriving from ViewPage), I get the error “CS0103: The name ‘Method’ does not exist in the current context” unless I use the this keyword to call it:

<%: Method() %> <!-- gives error CS0103 -->
<%: this.Method() %> <!-- works -->

Why is the this keyword required? Or does it work without it, but I’m missing something?

(I think there must be a duplicate of this question, but I was not able find one)

Update:

As Ben Robinson says, the syntax to call extension methods is just compiler sugar. Then why can’t the compiler automatically check the for extension methods of the current type’s base types without requiring the this keyword?

  • 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-16T11:04:51+00:00Added an answer on May 16, 2026 at 11:04 am

    A couple points:

    First off, the proposed feature (implicit “this.” on an extension method call) is unnecessary. Extension methods were necessary for LINQ query comprehensions to work the way we wanted; the receiver is always stated in the query so it is not necessary to support implicit this to make LINQ work.

    Second, the feature works against the more general design of extension methods: namely, that extension methods allow you to extend a type that you cannot extend yourself, either because it is an interface and you don’t know the implementation, or because you do know the implementation but do not have the source code.

    If you are in the scenario where you are using an extension method for a type within that type then you do have access to the source code. Why are you using an extension method in the first place then? You can write an instance method yourself if you have access to the source code of the extended type, and then you don’t have to use an extension method at all! Your implementation can then take advantage of having access to the private state of the object, which extension methods cannot.

    Making it easier to use extension methods from within a type that you have access to is encouraging the use of extension methods over instance methods. Extension methods are great, but it is usually better to use an instance method if you have one.

    Given those two points, the burden no longer falls on the language designer to explain why the feature does not exist. It now falls on you to explain why it should. Features have enormous costs associated with them. This feature is not necessary and works against the stated design goals of extension methods; why should we take on the cost of implementing it? Explain what compelling, important scenario is enabled by this feature and we’ll consider implementing it in the future. I don’t see any compelling, important scenario that justifies it, but perhaps there is one that I’ve missed.

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

Sidebar

Related Questions

I have created my own extension as: public static MvcHtmlString hSearch(this HtmlHelper helper, string
In our ASP.NET MVC project, we have an HtmlHelper extension method to generate a
i have this code in one of my asp.net mvc views: <%Html.RenderFile(@C:\Members\newsletters\welcome.html);%> I have
I have created an HtmlHelper Extension method which returns an encoded string, I have
I created an extension method that uses the built-in ASP.NET serializer to serialize my
I created the following extension method for a ViewPage: using System.Web.Mvc; namespace G3Site {
How I can create an extension method like Html.DisplayTextFor in Asp.net mvc ? I
I have created a Extension method for IQueryable class to convert list of a
I can have an extension method like this: DateTime d = new DateTime(); d
This question relates to ASP.NET MVC 2 RC (December drop). The basic problem is

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.