MVC :: Wrap IsAjaxRequest() And Other Extension Methods With DI For Testability?

Mar 21, 2010

I'm using IOC containers that wrap items of HttpContext, such as Request and Session variables, to simplify mocking of it for testability.

Since IsAjaxRequest() is an extension method, it doesn't show up in HttpContext.Current.Request.

Is it possible to wrap extension methods with a IOC container? How?

View 11 Replies


Similar Messages:

Using Extension Methods In Static Methods On Extended Classes?

Aug 16, 2010

I have an extension method as follows:

public static class PageExtensions
{
public static int GetUserId(this Page targetPage)
{
var user = Membership.GetUser(targetPage.User.Identity.Name);
return (int)user.ProviderUserKey;
}
}

Now in a page I need to use this method in a static WebMethod, so I have added another 'extension method' to PageExtensions:

public static int GetUserId()
{
return (int)Membership.GetUser(HttpContext.Current.User.Identity.Name).ProviderUserKey;
}

and I call it as follows in my WebMethod: PageExtensions.GetUserId()

View 1 Replies

Web Forms :: How To Change This Methods In To Use Dictionary Or Extension Methods

Jul 23, 2010

public class CacheHelper { /// <summary> /// Removes object with the specified key. /// </summary> /// <param name="key">The key.</param> [code]....

I have this methods for caching..I need to change this methods to use in aDictionary<string,object>

How do I need to change this code Because I am new to asp.net I am still learning..

View 12 Replies

C# Extension Methods For C# In General (.Net 3.5)?

Dec 6, 2010

I'm searching for some extension methods that helps programming in ASP.NET. Some functions to work on controls, validators, AJAX or programing in C# in general.It could be methods library or your own methods.Do you know any source of those methods (other than CodePlex - that is good source of generic extensions) especially for ASP.NET?

View 1 Replies

WebMatrix :: Interesting Problem About @ And Extension Methods?

Oct 22, 2010

Note , that i'm new to c# so it might not be a problem.first , what is the exact meaning of @ in Razor ?does it mean WebPage.Response.Write ?next, i designed an extension method to WebPage ( by the way that is the coolest feature ever in c# )in my Razor code , to use it in a webpage , i must write @this.MyExtensionMethod() instead of @MyExtensionMethod().So why is it? because @this.MyExtensionMethod() and @MyExtensionMethod() should be the same ?

here is my extension method :

[Code]....

View 5 Replies

Razor Support Of Generic Extension Methods?

Feb 11, 2011

With regards to the Razor view engine, say I want to render Html.TextBoxFor<SomeModel>(i => i.Name), it doesn't seem that the inline syntax works as in:

@Html.TextBoxFor<SomeModel>(i => i.Name)

This doesn't seem to work because it interprets the generic as an HTML tag. I could use a code-block approach, but then what's the best approach to output the content? The HTML string returned from this method, do I response.write it, or is there a syntax for it, or what's the approach?

View 2 Replies

MVC :: How To Create An Extension To Extend The HtmlTextbox Methods

Sep 16, 2010

I am trying to create an extension to extend the HtmlTextbox methods to allow our developers to add onkeydown inline javascript to auto click a button with a name they specify.

[Code]....

View 6 Replies

Configuration :: Unable To Access Extension Methods

Oct 14, 2010

I have a web site project using the .NET 2.0 Framework that I am working on in Visual Studio 2008. I am using a third-party DLL in my project. I have added a reference to the DLL in my project and I can use everything as expected, including a number of extension methods for certain objects. Intellisense sees these extension methods, and I am able to make use of them and I can build my project on my local machine without any errors.

However, when running my website on a production server, I get a Compilation Error saying that the extension method I am trying to use could not be found. I can use everything else in the DLL besides the extension methods on the production server.

This is my first exposure to extension methods and understand what they are, but I can't seem to figure out why I can't make use of these methods outside of my local machine.

View 2 Replies

MVC :: Extension Methods To Search Jquery Grid?

Apr 5, 2010

I have jquery grid I need to search the grid results..

I thogught best method to search like string,bool, decimal, byte..

better to write the extension methods?how to write the extension methods to search the jquery grid using asp.net mvc control..

View 1 Replies

MVC :: UrlHelper Extension Methods For Areas (Best Practices)

Apr 20, 2010

In the previous version of our application we worked one we used MVC 1, so no area's. Following the ASP.NET MVC Best Practices by Kazi Manhur, I Created Extension methods of UrlHelper to generate your url from Route


Now with the new version, we are using MVC 2 and Areas. I was just wondering if one should implement it as before or have a new "best practice" regarding this emerged?

What I'm doing right now is:

1) Create a route in my area's route registration:

[Code]....

2) Creat an UrlHelper Extension method:

[Code]....

3) then just call it like this:

[Code]....

While typing this I started wondering what is the use of the ID you specify for the Area route..cant one just call the route using that?

View 2 Replies

Use Extension Methods Inline In An ASPX Page?

Jan 15, 2010

Is it possible to do something like this inline in an ASPX page?

<%= Me.SomeExtensionMethod() %>

I can't seem to figure out how to get this to work properly. I'm receiving an error saying that "SomeExtensionMethod" is not a member of the current Page object. I've added the necessary <%@ Import Namespace="..." %> directive at the top of my page. This Does work in code-behind.This isn't vitally important, but it would be good to know how to do in the future.

View 2 Replies

MVC :: Creating HTML Helpers With Extension Methods?

Oct 18, 2010

namespace MvcLogin_Validation.Helpers
{
public static class LabelExtensions

[code]...

View 4 Replies

"GroupBy" And "OrderBy" Methods From LINQ As Extension Methods?

Mar 11, 2010

We say that "GroupBy" and "OrderBy" methods from LINQ as Extension Methods.Then how about "variable.ToString()" and "string.Split()" menthods. Are these Extension methods.

View 2 Replies

Web Forms :: Extension Methods And Customized Generic List Collections

Nov 19, 2011

How to use extension methods and customizes generic list collections??

View 1 Replies

How To Write Extension Methods For Both Nullable And Not Nullable

Nov 10, 2010

I've written the following Extension Method

<Extension()>
Public Function ToUtcIso8601(ByVal dt As Date) As String
Return String.Format("{0:s}Z", dt)
End Function

But I also need a Nullable version of the same method... how exactly do I do this?

This is what I was thinking, but I'm not sure if this is the right way

[code]....

View 1 Replies

MVC :: RenderPartial To String For JsonResult While Maintaining Testability?

Mar 28, 2010

I would like to wrap a RenderPartial in a JsonResult so that my jQuery can handle placement/positioning of the html data based on additional Json parameters.

e.g. {html: <string returned from RenderPartial>, typeofdata: 1}

After Googling, it seems that the only way to do this is a workaround that hijacks HttpContext in order to spit the PartialViewResult into a string. However, this seems like it would break testability.

Is JsonResult not intended to be used with RenderPartial?

Alternatively, I could set typeofdata as a parameter of the model, and have the PartialView render it as a hidden field, then have jQuery look for it. What is a better way to generate the data that I need?

View 5 Replies

MVC :: IsAjaxRequest Is Always False?

Mar 22, 2010

i am using MVC 2 RC and VS2010

when i want to use Ajax for my application IsAjaxRequest returns false

this is my code for view

[Code]....

and this is my controller

[Code]....

also i was added these libraries to my master page

[Code]....

the Request.IsAjaxRequest returns false

View 8 Replies

MVC :: OutputCache Varyby IsAjaxRequest?

Jan 11, 2010

I've an action in a controller that returns different content if the request is Ajax or not:

[Code]....

So, from the view I can fill a <div> with the PartialView (RenderPartial), calling the same action (allowing javascript disabled clients). The problem is the cache, because when the request has cached as a normal request, if later sends the request as an Ajax request, the view is rendered very bad.

The question is: Is there any way to use OutputCache to allow to cache in different entries this two types of requests (Ajax and not Ajax).

View 4 Replies

MVC :: IsAjaxRequest Method Doesn't Work With Some IE Requests

Sep 16, 2010

I've just discovered that the X-Requested-With header in IE is always "XMLHttpRequest, XMLHttpRequest" instead of just "XMLHttpRequest". I found the reason in MicrosoftMvcAjax.debug.js at line 280 (MVC 2.0). Seems there is no need to add this header again as it is already done in Microsoft AJAX Library. And because of this IsAjaxRequest extension method doesn't work anymore if there is no X-Requested-With param in the request body. And this make X-Requested-With header useless in IE.

In Firefox there is no problem as it doesn't append but replace the existing header value. Not tested in other browsers.

View 9 Replies

Ajax.ActionLink Is Not Working - Response.IsAjaxRequest() Is Always False

Feb 11, 2011

I have been googling/SO:ing this issue for a while and many seem to be sharing this, but I haven't found any successful solution to my problem.

Using MVC3 and Razor.

Master page contains:
<script src="@Url.Content("~/Scripts/jquery-1.5.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MicrosoftAjax.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MicrosoftMvcAjax.js")" type="text/javascript"></script>
AjaxTest.cshtml contains:
<div id="AjaxTestDiv">content</div>
@Ajax.ActionLink("Update", "AjaxTester", new AjaxOptions { UpdateTargetId = "AjaxTestDiv" })
AjaxTester action method:
public string AjaxTester()
{
if (Request.IsAjaxRequest())
{
return DateTime.Now.ToString();
}
else
{
return "FAIL";
}
}

I always get the "FAIL" returned, to a blank page, not in the targeted div.

Edit: Also note that if I remove the if (Request.IsAjaxRequest()), I still don't get back anything to the targeted div, but instead a blank page.

Edit2: Looking at the HTML generated, this is my link:

<a data-ajax="true" data-ajax-method="POST" data-ajax-mode="replace"
data-ajax-update="#AjaxTestDiv" href="/Area/AjaxTester">Update</a>

Have tried switching the method to GET, to no avail.

View 1 Replies

Want To Try And Test An Action Method On Controller That Itself Tests If IsAjaxRequest() Is True?

May 28, 2010

I'm just starting to use the TestHelpers in MvcContrib. I want to try and test an action method on my controller that itself tests if IsAjaxRequest() is true. I've used the same code that is shown in the TestHelper samples to set up the TestControllerBuilder

_controller = new StarsController();
_builder = new TestControllerBuilder();
_builder.InitializeController(_controller);

So that _controller has all the faked/mocked HttpContext inside it, which is really great. But what do I do now to force IsAjaxRequest() on the internally faked Request object to return true?

View 2 Replies

Security :: Not Extending MembershipProvider Class And Putting All This Methods In Some Unique Class And Call Its Methods Then?

Sep 16, 2010

I am beginner in web applications development. I started one little project and host it on source forge "https://homoco.svn.sourceforge.net/svnroot/homoco". And I started implementing authentication in this application to learn how it works. From my experience people never use out of the box things so I want to implement this stuff alone (like in real world projects). So some questions:

1) Is there any reason to use membership out of the box? To use database table schema, stored procedures etc. that tool generate for developer. I think that this lower control over code and I decided to implement it my self. I don't know if I am right.

2) Is my approach in this demo project good or bad (if someone have time I like to do just a little code review)? I created database based on business rules. Not using database schema that membership provider require. Extend "MembershipProvider" class to satisfy my needs. Implement queries to database myself.

3) Now, this question is a little wired but I have to ask it. If we make custom Membership Provider and do sql queries alone, implement all MembershipProvider class methods ourselves, and in application use Membership.blabla() why is this approach different from not extending MembershipProvider class and putting all this methods in some unique class and call its methods then? I hope that someone understand what I ask here.

I am sorry for three questions, but I really trying to find the best way to implement this feature in my demo project like it is a real world application.

View 3 Replies

How To Wrap Dll To Web Services

Jan 25, 2011

I am facing the situation in which i have to expose a dll (managed) through web services. Basically make everything from dll accessible to other applications through web services. The dll is a third party and i cannot give any other info on it , but my problem would not depend on this details.

I am looking for the latest best practices (latest tech) approach on how to start this. One thing i have been documented over was Web Service Software Factory, but i do not know how good would this approach be for my situation, and i would welcome some ideas based on experience ofc. The top things i liked and need in my project about the WS Factory were : SOAP faults handling , Entity Translator , Versioning (covering both forward and backward compatibility).

View 1 Replies

MVC :: Wrap A BindAttribute?

Mar 9, 2011

Consider this snippet below:

[Code]....

This works great, and it works how I want it to... But... I have lot's of methods that have this attribute.
Is there a way I can wrap this some how so I can just say ([CustomBind] MyListObject theList)?I of course tried to extend it, but the class is sealed.

View 1 Replies

How To Set Word Wrap In Asp:table

May 31, 2010

I want to know to set word wrap in asp table. I tried with cells.wrap=true, but no effect.

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved