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

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -