Question about using the new {}

I am currently working on the Apress ASP.NET MVC2 book and I am a bit confused about the user new {returnUrl} in the following code:

public RedirectToRouteResult RemoveFromCart(Cart cart, int productID, string returnUrl)
{
    Product product = productsRepository.Products.FirstOrDefault(p => p.ProductID == productID);
    cart.RemoveLine(product);
    return RedirectToAction("Index", new { returnUrl });
}

Is this somehow related to creating a new line, and not just passing a reference to the parameter passed to?

+3
source share
4 answers

Creates an anonymous type with a property returnUrlthat also matters returnUrl. So like this:

var anon = new { returnUrl = returnUrl };
return RedirectToAction("Index", anon);

Using a name from an expression to determine the name of a property in an anonymous type is called a projection initializer.

? , . # 3, LINQ.

+12

. "returnUrl".

URL- ActionResult .

0

. " " . .

0

All Articles