Firstly you are using $.getJSON method and it send data through HTTP GET method. Secondly you want to post a complex object from javascript to server which not good(not possible also). It will work if you have simple data like as employeeID not employee object. Hope you get the point.
Next how to overcome your problem:
Step 1: Add model class to model folder
public class Category
{
public List<string> ID { get; set; }
public List<string> Name { get; set; }
public List<string> lgaID { get; set; }
public List<string> lgaName { get; set; }
public int IDTest { get; set; }
}
}
Step 2: Add action to Controller
[HttpPost]
public ActionResult getLGA(Category catObject)
{
try
{
Category c = new Category();
char[] chars = { ',' };
for (int i = 0; i < 10; i++)
{
c.lgaName.Add("Manas - " + i.ToString());
}
return Json(c.lgaName, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
throw ex;
}
}
Step 3: Add code in view page.
<select id="schllga" class="form-control-select" required></select>
<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<script>
var tempObject = ["Manas", "Hero"];
var jsonObj = { catObject: { ID: null, Name: null, lgaID: null, lgaName: tempObject, IDtest: 29 } };
$.ajax({
type: "POST",
url: "/Home/getLGA",
data: JSON.stringify(jsonObj),
contentType: "application/json",
datatype: "json",
success: function (costs) {
var $sel = $("#schllga");
$sel.empty();
$.each(costs, function (index, element) {
alert(index);
$("<option/>").text(element).appendTo($sel);
});
}
});
Note: You may change your logic inside controller action.