Getting values of dynamically added elements
I cannot get the value of my dynamically added elements with jquery.
public IEnumerable<GroupDetail> GroupDetaile { get; set; }
returns as null
!
What should I do to get the values?
My Model:
public class elementmodel
{
public group MyGroup { get; set; }
public IEnumerable<GroupDetail> MyGroupDetail { get; set; }
}
My View:
function new() {
var items = '@foreach(SelectListItem item in (SelectList)ViewData["Ceasers"]){<option value="@item.Value">@item.Text</option>}'
i = i + 1
$("#mytable").append("<tr><td><div id='dive" + i + "'><select name='MyGroupDetail[" + i + "].cea_id'>" + items + "</select><input type='button' value='-' id='buttonminus" + i + "' class='bumblebutton' style='width:5%;' onclick='removeelem(" + i + ")' /></div></td></tr>");
}
I want to fill this with my dynamically added elements value field:
public I开发者_如何学CEnumerable<GroupDetail> MyGroupDetail { get; set; }
I tried to do it by using this method:
name='MyGroupDetail[" + i + "].cea_id'
but somehow I still get the null value..
ok found it! My code up there works what i just needed is starting with 0
$('document').ready( function() {
var items = '@foreach(SelectListItem item in (SelectList)ViewData["Ceasers"]){<option value="@item.Value">@item.Text</option>}'
i = 0;
$("#mytable").append("...<select name='MyGroupDetail[" + i + "].cea_id'>" + items + "</select>...");
});
it's all cause of : public IEnumerable<GroupDetail> MyGroupDetail { get; set; }
IEnumerable
items always starts with 0
so dynamic elements should start with 0
too for getting the values back.
精彩评论