Snake Eyes
Snake Eyes

Reputation: 16764

Add automatically anonymous properties to routeValues which is object in ASP.NET MVC4 ActionLink

I use this ActionLink method in order to generate method.

LinkExtensions.ActionLink Method (HtmlHelper, String, String, Object)

Sot the 4th parameter is an Object which contains anonymous properties, used for routes.

It is possible to append/add automatically new anonymous properties to existing routeValues which is Object ?

If yes, how ?

Let's assume that I have a method:

public void Test( ref object currentRouteValues, string newValue)
{
    if(!string.IsNullOrEmpty(newValue)){
       // add a custom property here to currentRouteValues
       // something like: (is wrong but I don't know how to proceed)
       currentRouteValues = new { currentRouteValues, myCustoProperty = newValue };
    }
}

How to do that automatically for above method ?

Thanks

Upvotes: 0

Views: 724

Answers (1)

Rickard Liljeberg
Rickard Liljeberg

Reputation: 1018

I think this would answer your question.

Merging anonymous types

If you simply want to extract the data it would be something like this.

        Object o = new { var1 = "the first var", var2 = "the second var" };

        System.Type type = o.GetType();

        foreach (var i in type.GetProperties())
        {
            Console.Write(i.GetValue(o));
        }

But for merging, look at the link above.

Upvotes: 1

Related Questions