Great article: DataContext vs ItemsSource (in Binding case)
The difference is that when using DataContext, it means that you bind the owner object of DataContext with the reference, which is DataContext pointed to. So, it some cases such as DataGrid or ListBox. We use ItemSource instead when we're talking about data in each row, not the DataGrid itself. On the other hand, we use DataContext to set binding from source ojbect to DataGrid directly.
Pages
Profile
|
Hi, I'm Veerapat Sriarunrungrueang, an expert in technology field, especially full stack web development and performance testing.This is my coding diary. I usually develop and keep code snippets or some tricks, and update to this diary when I have time.
Nowadays, I've been giving counsel to many well-known firms in Thailand.
view more... |
Saturday, July 30, 2011
Thursday, July 28, 2011
How to pass Dynamic Anonymous Object to ViewPage in Razor
Normally, you can't pass anonymous object as a model to ViewPage because it can only be accessed from within the assembly in which it’s declared. Since views get compiled separately, the dynamic binder complains that it can’t go over that assembly boundary. So, to solve this problem we have to create own ViewPage that use dynamic object as a Model, or create extension method to change its type to ExpandoObject.
Using ExpandoObject:
Then, you can pass anonymous object through Model, and use it as dynamic object.
References: http://stackoverflow.com/questions/5120317/dynamic-anonymous-type-in-razor-causes-runtimebinderexception, http://blogs.msdn.com/b/davidebb/archive/2009/12/18/passing-anonymous-objects-to-mvc-views-and-accessing-them-using-dynamic.aspx
Using ExpandoObject:
public static ExpandoObject ToExpando(this object anonymousObject) { IDictionaryanonymousDictionary = HtmlHelper.AnonymousObjectToHtmlAttributes(anonymousObject); IDictionary expando = new ExpandoObject(); foreach (var item in anonymousDictionary) expando.Add(item); return (ExpandoObject)expando; }
Then, you can pass anonymous object through Model, and use it as dynamic object.
References: http://stackoverflow.com/questions/5120317/dynamic-anonymous-type-in-razor-causes-runtimebinderexception, http://blogs.msdn.com/b/davidebb/archive/2009/12/18/passing-anonymous-objects-to-mvc-views-and-accessing-them-using-dynamic.aspx
Labels:
ASP.NET,
MVC,
Programming
Wednesday, July 27, 2011
Comparison of NoSQL
Nowadays, there are many NoSQL tools or engines to use. Some people may not know which one should be used. Let's see the NoSQL comparison to know their strength and weakness here: http://kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-vs-redis. If you don't know what NoSQL is, take a look here: http://en.wikipedia.org/wiki/NoSQL.
Labels:
Database Technology,
NoSQL
Subscribe to:
Posts (Atom)