Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access

后端 未结 4 2213
青春惊慌失措
青春惊慌失措 2021-01-01 11:26

I\'m trying to add additional attribute data-icon to my Action Link, but I\'m getting the error below:

Invalid anonymous type member

4条回答
  •  南笙
    南笙 (楼主)
    2021-01-01 12:00

    I just use the following

    @using System.Web.Routing
    
    @{
        RouteValueDictionary RouteValues = new RouteValueDictionary();
    
        RouteValues["id"] = 11;
        RouteValues[Some_Name] = Some_Value; //do this with as many name/value pairs 
                                             //as you like
    }
    
    @Html.ActionLink("Link Text", "Action", "Controller", RouteValues)
    

    which I learnt from Jon's answer in this post.

    I have mainly used this in my controllers to provide the route values for RedirectToAction() methods, but i don't see why it shouldn't work in your view, you will need to add a @using System.Web.Routing; though.

提交回复
热议问题