I have an ajax call to an action method which returns a partial view with a CarViewModel.
It returns a response with the following format:
Honda
Lovely Car
Forde
Comfortable Car
.cshtml
<h3 data-car-id="@Model.Id">@Model.CarTitle</h3>
<p>@Model.CarDescription</p>
Ajax
success: function (data) {
$("div").append(result);
}
Before appending result into DOM I need to check the value of data-car-id, if there is a data-car-id in dom with the same value, I'd like to append that specific car differently to one with a unique data-car-id.
I'm struggling to tackle this problem, as data returns multiple cars at once. I imagine I'd somehow need to parse each car within the html into its own variable?
Updated with full Ajax
$.ajax({
url: '/Home/GetData/',
type: "GET",
success: function (data) {
if (data == null) {
} else {
$(".div").append("<div class='cars'>" + data + </div>");
}
}
});