Search code examples
c#urlhelper

How to solve "invalid anonymous type member decelerator" error


I have created an Extension function for UrlHelper which simplifies the writing of parameters. It just accept two string parameters and return a string of desired format. In my case it work like this:

public static string CustomAction(this UrlHelper helper, string key, string value)
{
    return HttpUtility.UrlEncode("(" + key + "=" + value + ")");
}

The problem I am facing now is when I use this function inside the URL.ACTION more than once it gives me an "invalid anonymous type member decelerator" error. Can someone tell me how can I solve this problem?

Example:

Url.Action("someAction", "someController", new { where = Url.CustomWhereAction("user.ID", Url.UrlParams("id")), Url.CustomWhereAction("person.ID", Url.UrlParams("id")) })

Just to clarify:

Url.UrlParams()

is another Extension function which avoids the programmer to write the code for extracting the routeData values.


Solution

  • you have

    Url.Action("someAction", "someController", new {
     where = Url.CustomWhereAction("user.ID", Url.UrlParams("id")), 
     Url.CustomWhereAction("person.ID", Url.UrlParams("id"))
    })
    

    this is invalid syntax you mean

    Url.Action("someAction", "someController", new {
     where = Url.CustomWhereAction("user.ID", Url.UrlParams("id")), 
     where2 = Url.CustomWhereAction("person.ID", Url.UrlParams("id"))
    })