Dr.Ajay Kashyap

Dr.Ajay Kashyap

  • NA
  • 521
  • 284.1k

How To Pass Array through Json In MVC

Feb 7 2017 9:50 AM
I want to pass Array Through json
 
<script type="text/javascript">
$("#Category").focusout(function () {
debugger;
var Category1 = $("input[name='[0].Category']").val();
var Category2 = $("input[name='[1].Category']").val();
var Category3 = $("input[name='[2].Category']").val();
var Category4 = $("input[name='[3].Category']").val();
var Category5 = $("input[name='[4].Category']").val();
 
var allcat = [ Category1, Category2, Category3, Category4, Category5 ];
var url = '@Url.Action("CheckCategory_Name", "CategoryAndSubCategory")';
$.getJSON(url, {Total :allcat }, function (data) {
if (data.isDuplicate == true) {
$("#Category").val("");
swal("The Category Name Is Already Exist");
return false;
}
});
});
</script>
 
[HttpGet]
public JsonResult CheckCategory_Name(string[] Total)
{
bool isDuplicate = false;
var categoryname = db.MasterCategories.ToList();
var jsonData = new { isDuplicate };
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
 
 

Answers (1)