I have a view which needs to display a table of data. Lets just say people.
So in my web api app, I create the view that could use razor to allow me to display these people:
@foreach(Person person in Model.People)
{
<tr>
<td>@person.FirstName</td>
<td>@person.LastName</td>
</tr>
}
I'm not even using the ApiController class yet.
So then lets say the user enters in some criteria in a search and the Model.People list needs to update. I would then use my controller (I think) to update my Model.People list. This is the functionality I need.
BUT I could use ALSO jQuery to hit my restful ApiController class, and dynamically update my people table something like this (although I don't think I have the syntax right):
$.getJSON('api/people/updatepeople', function(data) {
var fileTable = $("#personTable");
$.each(data, function() {
var row = $('$(this).Name$(this).FirstName', '$(this).Name$(this).LastName');
$("#personTable").append( row );
});
});
Syntax aside, what should I be doing? Razor or jQuery? Is it better or more efficient to use razor with models and a Controller, with no ApiController? Or use jQuery with an ApiController? It seems these technologies go hand in hand, razor with a controller, jQuery with a ApiController. I feel like I shouldn't be mixing them, like using jQuery with razor and models...?
Would appreciate any insights into what is the more correct approach (if there is one) and why.