I am pulling some data from an Web API using JQuery Ajax as follows:
<script>
$(document).ready(function () {
$.ajax({
type: 'GET',
url: 'http://localhost:43618/api/Products',
dataType: 'json',
success : function(data) {
//some code goes here
}
});
});
</script>
Now, I would like to bind the pulled data to the MVC Model in the following view:
@model IEnumerable<CosumingWebAPIJQuery.Models.Product>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Price)
</th>
<th></th>
</tr>
@if (Model != null)
{
foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Price)
</td>
</tr>
}
}
</table>
So how can I convert the pulled JSON data into MVC Model Object and bind it to the View to show the data in a list?? Any Help Please??