c# - MVC - Assigning Values to Dictionary -
i trying add dictionary values in view, following code :-
public class { public int employeeid { get; set; } public int employeename { get; set; } public dictionary<string, double> dic1 { get; set; } public dictionary<string, double> dic2 { get; set; } } view :-
@model list<models.to> @for (int = 0; < @model.count; i++) { @html.hiddenfor(m => m[i].employeeid) @html.hiddenfor(m => m[i].employeename) .... @html.hiddenfor(m => m[i].dic1, value = "") // psuedo } as have assigned values employeeid & employeename in post method in controller, how assign values dictionary?
you can't put whole dictionary hidden field. dictionary enumerable, have work out each key/value.
@for (int = 0; < @model.count; i++) { @html.hiddenfor(m => m[i].employeeid) @html.hiddenfor(m => m[i].employeename) .... foreach (string key in dic1.keys) { @html.hiddenfor(m => m[i].dic1[key]) } }
Comments
Post a Comment