Я использую jquery-tmpl
и получаю следующие JSON
данные, которые я использую для проверки формы в ASP.NET MVC3:
{"Status":1,"Message":"Oh dear, what have you done. Check the list of errors dude!","Errors":["The Contents field is required.","The Date Created field is required.","The Date Updated field is required.","The Updated By field is required."]}
Мой шаблон выглядит так:
<script id="ResponseTemplate" type="text/x-jquery-tmpl">
{{each(i, error) Errors}}
<li>${error}</li>
{{/each}}
</script>
Мой JSON
POST выглядит следующим образом:
var data = {
Contents: "This is a test",
DateCreated: "",
DateUpdated: "",
UpdatedBy: "Ben"
};
$.ajax({
url: '@Url.Action("save", "note")',
data: JSON.stringify(data),
type: 'POST',
contentType: 'application/json',
dataType: 'json',
success: function (result) {
alert(result.Errors);
$("#Responses").tmpl(result).appendTo("#ResponseTemplate")
}
});
Данные верны. Предупреждение показывает массив ошибок в виде строки. Шаблон просто не работает.
Ответ должен быть простым.