Hi,
use the ajax post method
ex. in view java scriopt (note S3 is @HtmlEditFor u can use input type=text too)
var S3 = ($('#S3').val())
City.push(S3.toString());
$.ajax({
type: "POST",
url: "/EmpLoyee/Focus",
data: JSON.stringify(City),
contentType: "application/json; charset=utf-8",
dataType: "json",
traditional: true
});
in Controller
public ActionResult Focus(string[] City)
{
foreach (var item in City)
{
if (item.ToString()=="NA")
{
OBJEmployee.PresentCity = "NO City";
PersonCity = "NO City";
TempData["CityLov"] = PersonCity;
}
}
return View();
}
if you want to play with html table you should work like this.
view:
<input type="button" onclick="myCreateFunction()" value="Add New Row" />
<input type="button" onclick="myDeleteFunction('2')" value="Delete row" class="hidden" />
<table id="TB1" class="table table-bordered table-striped">
<tr>
<th>Qualification</th>
<th>PassingYear</th>
<th>Division</th>
<th>Percnet</th>
<th>Institute</th>
<th>Remark</th>
<th class="hidden">EmpID</th>
<th></th>
</tr>
<tr>
<td><input type="text" value="" /></td>
<td><input type="text" value="" /></td>
<td><input type="text" value="" /></td>
<td><input type="text" value="" /></td>
<td><input type="text" value="" /></td>
<td><input type="text" value="" /></td>
<td class="hidden"><input type="text" value="" /></td>
<td><input type="button" onclick="getId(this)" value="Delete row" /></td>
</tr>
<tr>
<td><input type="text" value="" /></td>
<td><input type="text" value="" /></td>
<td><input type="text" value="" /></td>
<td><input type="text" value="" /></td>
<td><input type="text" value="" /></td>
<td><input type="text" value="" /></td>
<td class="hidden"><input type="text" value="" /></td>
<td><input type="button" onclick="getId(this)" value="Delete row" /></td>
</tr>
<tr>
<td><input type="text" value="" /></td>
<td><input type="text" value="" /></td>
<td><input type="text" value="" /></td>
<td><input type="text" value="" /></td>
<td><input type="text" value="" /></td>
<td><input type="text" value="" /></td>
<td class="hidden"><input type="text" value="" /></td>
<td><input type="button" onclick="getId(this)" value="Delete row" /></td>
</tr>
</table>
<script>
function myCreateFunction() {
var table = document.getElementById("TB1");
var row = table.insertRow(table.length);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
var cell4 = row.insertCell(3);
var cell5 = row.insertCell(4);
var cell6 = row.insertCell(5);
var cell7 = row.insertCell(6);
cell1.innerHTML = "<input type='text' value='' />";
cell2.innerHTML = "<input type='text' value='' />";
cell3.innerHTML = "<input type='text' value='' />";
cell4.innerHTML = "<input type='text' value='' />";
cell5.innerHTML = "<input type='text' value='' />";
cell6.innerHTML = "<input type='text' value='' />";
cell7.innerHTML = "<input type='button' onclick='getId(this)' value='Delete row' />";
}
function myDeleteFunction(id) {
document.getElementById("TB1").deleteRow(id.value);
}
</script>
<script>
function SendData() {
var myTab = document.getElementById('TB1');
var Details = [[]];
for (i = 1; i < myTab.rows.length; i++) {
Details.push([myTab.rows[i].cells[1].children[0].value, myTab.rows[i].cells[2].children[0].value, myTab.rows[i].cells[3].children[0].value]);
};
$.ajax({
type: "POST",
url: "/EmpLoyee/Create",
data: JSON.stringify(Details),
contentType: "application/json; charset=utf-8",
dataType: "json",
traditional: true
});
}
</script>
Class:
public class Details
{
public string Qualification { get; set; }
public string PassingYear { get; set; }
public string Division { get; set; }
public string Percnet { get; set; }
public string Institute { get; set; }
public string Remark { get; set; }
}
in Controller
public ActionResult Create(EmployeeDAL OBJ, List<Details> Details, List<Details> Details2)
{
if (Details!=null)
{
foreach (var item in Details)
{
string q = item.Qualification;
}
}
return view();
}
I think you got the ruff idea how to do it. thanks