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
Similar Messages:
Sep 3, 2010
Trying out the Razor view engine and for some reason my generic helper methods are breaking. For example:
public static class UrlHelperExtensions
{
public static string NonGenericHelper(this UrlHelper helper, Type controller)
{
return controller.Name;
}
public static string GenericHelper<TController>(this UrlHelper helper)
{
return typeof(TController).Name;
}
}
Works as expected:@Url.NonGenericHelper(typeof(ProjectEuler.UI.Models.Home))Breaks with the following exception:
@Url.GenericHelper<ProjectEuler.UI.Models.Home>()
"CS1502: The best overloaded method match for 'Microsoft.WebPages.WebPageUltimateBase.Write(Microsoft.WebPages.Helpers.HelperResult)'
has some invalid arguments"
The only workaround I could find is treating it as a "multi-token
statement":
@(Url.GenericHelper<ProjectEuler.UI.Models.Home>())
Not sure if this is the intended behavior or just a bug but it would be nice to be able to call a generic method as you would a non generic one.
View 2 Replies
Nov 19, 2011
How to use extension methods and customizes generic list collections??
View 1 Replies
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
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
Apr 14, 2010
I need to get an image from a SQL Server as a byte[], and load it to a WebControl.Image. The only seemingly good way to do it that I found is to implement IHttpHandler and handle the request accordingly.But I'm stuck to using asp.net 1.1. Does it support ashx files?
View 1 Replies
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
Apr 2, 2011
I am facing serious problem while trying to work in clientevents provided with asp.net mvc telerik grid.
Here's the two different scenarios:When I am putting the following script in a view or partial view it works fine;
<%= Html.Telerik().Grid()
.Name("Grid")
.DataKeys(keys => keys.Add(p => p.StaffId))
[code]...
View 1 Replies
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
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
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
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
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
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
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
Oct 18, 2010
namespace MvcLogin_Validation.Helpers
{
public static class LabelExtensions
[code]...
View 4 Replies
Oct 1, 2010
Is something like the below possible?
public static T Sum<T>(this DataTable dt, string columnName)
where T : IEnumerable<decimal>, IComparable<decimal>[code]....
It feels like i'm almost there, but not quite :/
Just trying to sum up either decimal or int values in a column in datatable. Currently getting a compile error, however think this is due to the incorrect generic constraint.
View 3 Replies
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
Feb 24, 2011
I manage a large asp.net site which has previously been converted from static html site to asp.net. For several reasons (mainly SEO) we decided not to rename all the files to .aspx back when we originally converted the site. This was very easy to do by simply adding the buildProvider and httpHandler to the web.config.
<buildProviders>
<add extension=".html" type="System.Web.Compilation.PageBuildProvider"/>
</buildProviders>
<httpHandlers>
<add path="*.html" verb="*" type="System.Web.UI.PageHandlerFactory"/>
</httpHandlers>
Now I am upgrading the site to use Asp.net WebPages with Razor cshtml files. I can rename all the files if necessary, and use url rewriting to make the urls stay the same, however it would be much easier if I could just configure the web.config to tell it to parse .html files as if they were .cshtml. I have searched around quite a bit, and could not find anything equivalent to the PageHandlerFactory for razor pages. It appears as though it is just an internal mechanism in the .net 4.0 ISAPI handler.
The site is currently running on Windows 2003 server and IIS 6. We will be upgrading to 2008/IIS 7.5 in the near future, but I'd prefer not to wait for that. Is there any way to get the .html files to be parsed by razor as if they were .cshtml files?
View 2 Replies
Mar 5, 2011
I'm trying to create a validation layer that will contain methods to validate all my objects (in my Business Objects layer) .. but when I try to reference both the validation and business objects to each other I get a circular dependency error .. so I've decided to create a new layer (BLL) to validate the objects for me and I'll be able to reference both the validation and the object layers.
so I want to build some kind of class/interface -I don't know what fits more- to be like a generic type or a parent type that my method could accept it as a parameter and check for it's Name/ID property. Instead of defining a new method overload for each object type I have
Simplification
View 1 Replies
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
Nov 25, 2010
I'm trying to create a control out of a class I found, and one of the overridden functions is the following:
protected override void PerformDataBinding(IEnumerable data)
However, when I try to build the control I'm getting the error as shown in the subject. I've tried searching, and it seems the signature for the original function matches the one I have, and all other solutions I've seen uses the same signature.
View 3 Replies
Oct 30, 2010
What is the difference between generic and non-generic collection?
View 1 Replies
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
Mar 21, 2011
i have a repository class inside my model folder; this repositiry contains many methods , which are called from Action methods in the controllers; so my question is :- if i have a method insidle my model.reporsitory which calls a stored procedure, then can i call it an "action method"? or "action method" expression only apply to controller methods?
View 4 Replies