ASP.NET MVC: What if your model is just a Dictionary? -


(I'm new to MVC).

I do not have a model in my application Oh, in the sense of a class with property Oh no it is very easy: My users basically fill a bunch of string values ​​for different keys in the system. (The keys are arbitrary and are not known ahead of time, thus there is no pre-coded category) 1 .

My "model" is similar to:

  dictionary < String, string & gt;  

Pretty simple

As I understand that this model is binding, HTML helpers, model state, legalization summaries all rely on reflection of an arbitrary class' Properties But can they use the key / value in their dictionary instead?

For example, I might have:

  & lt; Label = "name" & gt; Name: & lt; / Label & gt; & Lt;% = Html.TextBox ("name")%> & Lt;% = Html Validation message ("name", "*")%> [AcceptVerbs (HttpVerbs.Post)] Create public action roles (dictionary & lt; string, string & gt; values ​​entered) {/ code>  

and:

  / ...}  

and my dictionary & lt; String, string & gt; Use the "name" key / value of MVC as found in "Model" Is Magic behind the scenes? (MVC 1.0 preferably, but please put some light, if it is better addressed in 2.0, as I still want to know)?


1: I'm sure silly. This is for a reporting app, where "keys" are the report parameter names and "value" are those that will run with the report.

The default model binder in MVC 1.0 can be billed in a dictionary unless it Magic form uses the field identifier 'index' [index] .key '' and 'dictation [index]'. Value 'where the name of the name is your nominal parameter name, and the index is a 0-based sequential number . Usually the 'key' value will be hidden fields, and the 'value' value is your text field. In your example:

  & lt;% = Html.Hidden ("value entered [0] .key", "name")%> & Lt;% = Html.TextBox ("Allocated values ​​[0] .value")%> & Lt;% = Html Validation message ("values ​​specified [0] .value", "*")%>  

As I understand, bindings for dictionaries are different MVC 2.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -