I am developing an application in ASP.NET MVC. I am working on a page that takes some user-entered values and then retrieves a dataset from them using a stored procedure. My preference is that the data is entered on the same page as on the display, so I use AJAX and partial views for this. My code worked fine with a dummy set of simple data (a simple line), but now when I use a more advanced data set (Ienumerable), it no longer displays a partial view.
Here is part of my view (the text fields into which data is entered are hidden for length purposes):
<div id="search-results">
</div>
<script>
function getSearchResults() {
var SqlViewModel = {
}
$.ajax({
type: "POST",
data: JSON.stringify(SqlViewModel),
dataType: "json",
contentType: "application/json",
url: "/Sql/Search/",
success: function(result) {
$('#search-results').html(result);
}
}); }
</script>
, "", ajax. ( SqlVieWModel)
:
[HttpPost]
public ActionResult Search(SqlViewModel sT)
{
var sql =
SqlPartialViewModel obj = new SqlPartialViewModel();
obj.SqlData = sql;
return PartialView("_SearchResultsPartial", obj);
SqlPartialViewModel:
public class SqlPartialViewModel
{
public IEnumerable<Get_Result> SqlData { get; set; }
}
, (_SearchResultssPartial.cshtml):
@model SqlPartialViewModel
<table>
<tr>
<th>//Display stuff</th>
</tr>
@foreach(var result in Model.SqlData)
{
<tr>
<td>//Display stuff</td>
</tr>
}
, .