javascript - Posting values from dynamically created table rows to ActionResult in a Controller -
i'm struggling piece of code, i'm beginner in mvc , web technologies in general , received project friend practice it, , saw 1 confusing part!
he adding rows bootstrap table dynamically. idea post list objects rows, many rows objects.
here example of how rows looks:
here example of entity
:
public class parameters : basedateentity { public decimal value1{ get; set; } public decimal value1{ get; set; } public decimal value1{ get; set; } public decimal value1{ get; set; } }
and idea post list of object "parameters" actionresult method, , famous code looks strange me, , can't values textboxes cause don't know how handle cuz don't understand it:
var modellistitem = function (item) { $('<input/>', { id: "hiddenselectedtableitemindex_" + item.id, name: "parameters.index", type: "hidden", value: item.id, class: "hiddenselectedtableitemclass_" + item.id }).appendto('#selectedtableitems'); $('<input/>', { id: "hiddenselectedvalue1tableitem_" + item.id, name: "parameters[" + item.id + "].value1", type: "hidden", value: 00000, class: "hiddenselectedtableitemclass_" + item.id }).appendto('#selectedtableitems'); $('<input/>', { id: "hiddenselectedvalue2tableitem_" + item.id, name: "parameters[" + item.id + "].value2", type: "hidden", value: 111111, class: "hiddenselectedtableitemclass_" + item.id }).appendto('#selectedtableitems'); $('<input/>', { id: "hiddenselectedvalue3tableitem_" + item.id, name: "parameters[" + item.id + "].value3", type: "hidden", value: 222222, class: "hiddenselectedtableitemclass_" + item.id }).appendto('#selectedtableitems'); $('<input/>', { id: "hiddenselectedvalue4tableitem_" + item.id, name: "parameters[" + item.id + "].value4", type: "hidden", value: 333333, class: "hiddenselectedtableitemclass_" + item.id }).appendto('#selectedtableitems'); } </script>
i describe javascript code, said in first block of code line : name: "parameters.index"
, means list called parameters submitted model, , said need $('<input/>', {
each property of class, 4 of blocks starting $('<input/>', {
because have 4 values submitted, can not understand how values associated values text boxes, testing purposes wrote value "00000, 11111 etc" , on form enter different values , looks this:
and when post server, there 3 object in list called "parameters", 0 values inside:
so guys kind of great, because i'm begginer on stuffs, , hard figure out how stuffs working in example..
p.s if wondering item.id
, id
of year, because rows created/added table when year choosen modal..
edit:
when form loads, there popup years, , each year have 4 values ( input types shown on images ), when user choose example 2017, 4 inputs generated in images above, , here javascript method acctually invoked when user click on button adding year (which not shown on images because id) , other 4 textboxes, here js method:
var additem = function (item) { $("#selectedtableitems").append("<tr id='selectedtableitem_" + item.id + "'> + '<td><input id="value1_' + item.id + '" type="number" style="width:100px" value=" " /></td>' + '<td><input id="' + item.id + '"type="number" style="width:100px" value=" "/></td>' + '<td><input id="' + item.id + '"type="number" style="width:100px" value=" " /></td>' + '<td><input id="' + item.id + '"type="number" style="width:100px" value=" " /></td>' + '<td><a href="javascript:removeitem(\'' + item.id + '\')" class="btn btn-danger btn-xs"><i class="fa fa-trash-o"></i></a></td></tr>'); modellistitem(item); }
modellistitem allready explained above.
Comments
Post a Comment