.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

RenderAction with Lambda Expression in MVC 3.0 preview 1

Posted By:      Posted Date: September 29, 2010    Points: 0   Category :ASP.Net

Hi all, i have the following, which works:

@{Html.RenderAction("Detail", "Help", new { pageName = "press" });}

But instead i'd like to use a lambda expression to get away from the string bits. I tried using the following (which is the nearest approximation i could figure based on my limited knowledge of the engine):

@{Html.RenderAction<HelpController>(x => x.Detail("press"));}

But i get the following error:

The non-generic method 'System.Web.Mvc.Html.ChildActionExtensions.RenderAction(System.Web.Mvc.HtmlHelper, string, string, System.Web.Routing.RouteValueDictionary)' cannot be used with type arguments

However, i'm reading in the Apress MVC 2.0 book that it is in fact declared as a method that takes type arguments. Am i missing an assembly reference, or has it not been included in the MVC 3.0 Preview 1 build?

View Complete Post

More Related Resource Links

Implicit-type lambda expression: is it possible?

Hi all, i was plaing around with LINQ and lambda expressions. I was trying to find duplicated files in my system. After a while a realized that duplicated could mean: - same name - same size and extension - ....   So i wrote this code: DirectoryInfo rootDirectory = ....; var groupFiles = selector => rootDirectory.EnumerateFiles("*", SearchOption.AllDirectories).GroupBy(selector).Select(g => new { g.Key, Info = g, Count = g.Count() }).Where(g => g.Count > 1); var groupsByName = groupFiles(f => f.Name); var groupsBySize = groupFiles(f => new { f.Length, f.Extension}); But i get the following error: Error 1 Cannot assign lambda expression to an implicitly-typed local variable So i tryed to make the type explicit and i realized that is not so easy. So what i'm missing?! IMPORTANT. 'm not tying to have the code working. I can solve the issue by duplicating code (even if i hate to do that) I'm rtying to improve my skills with LINQ and Lambda Expressions. Thanks all!!  

MVC 3.0 preview 1, Html.RenderAction Problem


Hi all,

I'm trying to use Html.RenderAction with MVC 3.0 preview 1 and i'm getting an error. i have the following controller:

	public class HelpController : Controller
public ActionResult Detail(int id)
ViewModel.Title = "Help Title! " + id.ToString();
ViewModel.Content = "Help Content!" + id.ToString();

return View();

and in another controller, i'm trying to do:

@Html.RenderAction("Detail", "Help", new { id = 3 });

but i keep getting:
CS1502: The best overloaded method match for 'Microsoft.WebPages.WebPageUltimateBase.Write(Microso

Help tloading a dropdownlist using lambda expression??? o/


Hello everyone

Thank you for your time..

I´m trying to load one field from the table using Lambda

 public void Search()


            ddlcity.DataSource = companiesBLL.Find(e => e.city.Equals(e.ID_COMPANY)).ToList();



ddlcity = dropdown

id_city = main Id (primarykey of that table)

but i want to only load the city field from the table Company.

I´d appreciate if anyone could help me.


 public void Bairro()
            ddlBairro.DataSource = empresasBLL.Find(e => e.BAIRRO.Equals(e.ID_EMPRESA)).ToList();

Lambda expression


Hi guys,

Anybody please give me the example How to use Lambda expression in linq.please give a simple example and describe it also.


How to create a generic Lambda Expression


I Use entity framework 4.

Here is my model






Each time I want the text for one of these model, I execute this lambda expression p=> p.LangID == 1

Is it possible to create a generic lambda expression function that all of these model can use.?

How to use lambda expression to replace if-else


I have a list of possible nodes as a child of parent node, i need to compare the nodeName and if node name matches, i need to get the value and assign it to member variable.

public class Contacts
private string FirstName;
private string LastName;
  public LoadContacts(XmlNode contactNode)
    string[] names={
    foreach(XmlNode child in contactNode)
     if( child.Name == names[0])
       m_firstName = child.Value;
     if(child.Name == names[1])
       m_lastName = child.Value;

Is there a way of re-factor the same code with Lambda expression.

Thanks in Advance.


DRY with Lambda Expression (errors management)


In my current project, I have made a miracle with Lambda Expression. Have you ever implemented something like this:

    public abstract class GenericRepository<TEntity> : IRepository<TEntity> where TEntity : classIEntity
        private readonly ILog _logger;

        protected GenericRepository()
            : this(IoC.GetInstance<IUnitOfWork>(), IoC.GetInstance<ILog>()

Linq: how to share parameters between lambda expressions ?

When using Linq to objects, you will quickly feel the need to pass some parameters from a method to another but it's not so easy because each Linq method is not calling the following one. In a Linq sequence, each method is using the result computed by the previous one. So, local contexts are not visible from one method to another.
The compiler is using two technical different ways to let parameters go out of a method.

What is Lambda Expressions In LINQ

A lambda expression is an anonymous function that can contain expressions and statements, and can be used to create delegates or expression tree types.

All lambda expressions use the lambda operator =>, which is read as "goes to". The left side of the lambda operator specifies the input parameters (if any) and the right side holds the expression or statement block. The lambda expression x => x * x is read "x goes to x times x." This expression can be assigned to a delegate type as follows:

Localizing RequiredAttribute ASP.NET MVC 3 Preview 1



Has anyone got the Localization working for the RequiredAttribute? 

The below DisplayAttribute is localized properly but the RequiredAttribute is not. Any ideas?

[Required(ErrorMessageResourceType = typeof (Account), ErrorMessageResourceName = "ErrorNotation")]
[Display(Name = "UserName", ResourceType = typeof(Account))]
public string UserName { getset; }

change to lambda in linq


Hello my friends I tried to change this code to lambda but I could not pleaaaase help me:


  var inforeport = from m in db.Products where m.UnitPrice > info select new { unit=m.UnitPrice,name= m.ProductName };


[How??] Lamda expression with ByRef parameter


How to write lamda expression with ByRef/ref parameter in c# ??

The code below causing syntax error:

item.OnAction = (p1, p2, ref p3) => {
   return true;

item.OnAction = (p1, p2, & p3) => {
   return true;

Express Yourself: Encoding Videos Using Microsoft Expression Encoder 3 SDK


Video on the Web involves huge amounts of data. Learn the best way to manage and move that data with the help of Microsoft Expression Encoder 3.

Adam Miller

MSDN Magazine June 2010

Security Briefs: Regular Expression Denial of Service Attacks and Defenses


Microsoft security expert Bryan Sullivan believes denial-of-service blackmail attacks will become more common as privilege escalation attacks become more difficult to execute. He demonstrates how to protect your apps against regular expression DoS threats.

Bryan Sullivan

MSDN Magazine May 2010

Silverlight: Create Animations with XAML and Expression Blend


In this excerpt from his upcoming book, Laurence Moroney explains the basics of Silverlight animation and the animation tools available in Expression Blend.

Lawrence Moroney

MSDN Magazine August 2008

Silverlight: Create a Custom Expression Encoder Publishing Plug-In


Laurence Moroney demonstrates how to employ the Expression Encoder plug-in APIs by building and debugging a simple FTP upload plug-in.

Laurence Moroney

MSDN Magazine February 2008

Basic Instincts: Lambda Expressions


Sample the basic concepts of lambda expressions, explore their benefits, and witness how to use them to write more expressive programs.

Timothy Ng

MSDN Magazine September 2007

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend