c# - How to pass values of the javascript-created-textboxes to asp.net mvc3 controller? -


i want let user add many tag wants article, have these simple classes:

public class tag {     public string name { get; set; } }  public class article {     public list<tag> tags { get; set; }      public article()     {         tags = new list<tag>();     } } 

and controller looks this:

public class homecontroller : controller {     public actionresult index()     {         return view(new article());     }      [httppost]     public actionresult edit(list<tag> tags)     {                     //tags null here         return view();     } } 

in view have simple textbox link named "add", , submit button. when "add" clicked, calls javascript function take value entered , create new disabled textbox value, disabled textbox placed in specified div. when submit, posts home/edit. "add" part works fine, user can add many tags necessary on fly.

the problem is, when submitting, none of newly created disabled textboxes passed in parameters, tags parameter null. i've made sure textboxes generated have name of tags[0].name, tags[1].name, etc.

is option use $.ajax() or $.post()? have lot more textboxes , dropdowns collect user input have not shown here, , creating json out of them used in $.ajax or $.post seems not fun. hoping can make use of mvc model binding if possible.

any help/suggestion appreciated!

what can build list in javascript memory page.

so create tag object in memory

var tag= new {name=$('input-selector').val()}; 

and push object follows:

taglist.push(tag); 

when done adding tags can make ajax call server follows:

$.ajax( url:url, data: {tag=$.tojson(taglist)}, type: "post", datatype: "json", success: function () {} 

)

and should able use list object required data @ server.

let me know if works out you.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -