Hi mahesh213,
Check this example. Now please take its reference and correct your code.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
SQL
CREATE PROCEDURE [dbo].[Customers_GetCustomersByCountry]
@Country VARCHAR(20) = NULL
AS
BEGIN
SELECT CustomerId
,ContactName
,City
,Country
,PostalCode
FROM Customers
WHERE Country LIKE @Country + '%' OR @Country IS NULL
END
Controller
public class HomeController : Controller
{
// GET: /Home/
public ActionResult Index()
{
return View();
}
public JsonResult Search(string country)
{
NorthwindEntities entities = new NorthwindEntities();
List<Customer> customers = entities.CustomersByCountry(country).ToList();
var jsonResult = Json(customers, JsonRequestBehavior.AllowGet);
return jsonResult;
}
}
View
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#ddlCountry").on('change', function (e) {
$.ajax({
type: 'GET',
url: "/Home/Search",
dataType: 'json',
data: { country: $(this).find('option:selected').val() },
success: function (response) {
$('#tblCustomers').hide();
$('#tblCustomers tbody').empty();
$.each(response, function (i, item) {
var rows = "<tr>" +
"<td>" + item.CustomerID + "</td>" +
"<td>" + item.ContactName + "</td>" +
"<td>" + item.City + "</td>" +
"<td>" + item.Country + "</td>" +
"</tr>";
$('#tblCustomers tbody').append(rows);
});
$('#tblCustomers').show();
},
error: function () {
}
});
});
});
</script>
<select id="ddlCountry">
<option value="0">Select</option>
<option value="USA">USA</option>
<option value="UK">UK</option>
<option value="Canada">Canada</option>
</select>
<table id="tblCustomers" class="table table-striped" style="display: none;">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>City</th>
<th>Country</th>
</tr>
</thead>
<tbody>
<tr>
<td>Id</td>
<td>Name</td>
<td>City</td>
<td>Country</td>
</tr>
</tbody>
</table>
Screenshot