c# - pass key value pair to controller -
i've seen couple possible solutions messy me. have simple solution this?
model:
public class myclass { public keyvaluepair<int,string> field { get; set; } } get method in controller:
public actionresult index() { var model = new myclass(); model.field = new keyvaluepair<int, string>(1, "test"); return view(model); } view:
@model webapplication1.models.myclass @using (html.beginform("mymethod", "home", formmethod.post)) { @html.hidden("field", model.field); <input type="submit" value="submit" /> } post method in controller:
public actionresult mymethod(myclass input) { var x = input.field; .... } the key value pair not passed method comes empty. easiest way of getting 'field' passed controller?
replace following line , try it.let me know problem.
@html.hidden("field", model.field); to
@html.hiddenfor(m => m.field);
Comments
Post a Comment