in my partial view i have a foreach loop to show up a table
like this
<table id="tableid">
<thead>
<tr>
<th>column1</th>
<th>column2</th>
<th>column3</th>
</tr>
</thead>
<tbody>
foreach(mymodel item in ineumerable<mymodel>)
{
<tr onclick=getdetails(this)><td>@item.coloumn1value</td>
<td>@item.coloumn2value</td>
<td>@item.coloumn3value</td></tr>
}
this is in a partial view inside a view which i am populating with ajax call
now in my .js - i have to get the a dom element with rows so that i can make the whole table a json result and send it controller action again to show up but
when doing doucment.all.tableid.rows[]
- its rows are always 0 .
so not able to get the row wise information and do some manupulation and send it to controller
1st qs - is there any way to get the rows of this table ??
doucment.all.tableid.innerHTML
has the whole data like
'\n<thead> coulmn1 \r\n\r\n .......</tbody>
with all data
and doucment.all.tableid.outerHTML
has the whole data with tag
now how to make this to a dom element or how to make it a jsonobject or complex object so that i cn manupulate each row and send this whole table as a object to controller
when i click on any row , another partial view load in the bottom page with all three text boxes with each property of that single row and a button called save
@Html.TextBoxFor(m => m.coloumn1value)
@Html.TextBoxFor(m => m.coloumn2value)
@Html.TextBoxFor(m => m.coloumn3value)
<input type="button" value="save" onclick="savechanges()">
here they can edit it and if they click on the button save it will immediately show up in the above table
Now in my parent view there are are two divs
table placeholder is getting populated by an ajax call like this
var details = {
_ID: ID,
}
$.ajax({
url: "/MyController/GetTheTableForThisID",
type: "POST",
dataType: "html",
data: details,
success: function (data) {
$('#tablePlaceHolder').html(data);
}
});
where ID i am getting from preious page and _ID is model property
public PartialViewResult GetTheTableForThisID(MyModel model)
{
//loading the values in Ienumerable of this class to ietrate
return PartialView("tablepartialviewname",model) ;
}
when clicking in each row i am loading one row as ajax call
var details = {
_rowID
}
$.ajax({
url: "/MyController/GetDetailsForOneRow",
type: "POST",
dataType: "html",
data: details,
success: function (data) {
$('#editOneRowPlaceHolder').html(data);
}
});
in my controller its hiting
public partialViewresult GetDetailsForOneRow(MyModel model)
{
model._rowID =//doing some manupulation and getting all the three values
return PartialView("partialViewforOneRowDetails",model)
}