I have the following route data
object newsRoute = new
{
Area = "Admin",
Controller = "News",
Action = "Edit"
}
How can I append Title = “Hello” to the object routNews?
As in or similar
newsRoute.Append(Title = "Hello");
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
When you create the anonymous object you’ve effectively defined the properties of the anonymous class. I don’t think you’ll have much luck trying to redefine the type after the fact. You could create a new anonymous object with the new field and the original fields and copy the fields over, but I’m guessing you wouldn’t want to do this.
You say that the object represents routedata, in that case it is probably a good idea to convert the anonymous object into a RouteValueDictionary instance using the following method
http://msdn.microsoft.com/en-us/library/system.web.mvc.htmlhelper.anonymousobjecttohtmlattributes(v=VS.98).aspx
Once converted the object has normal dictionary semantics so you can add new key value pairs at will.
You should then be able to use the RouteValueDictionary to generate your urls