I search solution for my problem in search engine and stackoverflow.I find a lot of answer but nothing of them didn't help to me. Here is my controller:
[HttpGet]
public JsonResult Get()
{
var cl = new List<Category>();
cl.Add(new Category()
{
Name = "C#"
});
cl.Add(new Category()
{
Name = "MVC"
});
return Json(cl.ToList(),JsonRequestBehavior.AllowGet);
}
and category class is below:
public class Category
{
public string Name { get; set; }
}
In my view,I want to list each item in the data.
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
type: "GET",
url: '@Url.Action("Get","Category")',
contentType: "application/json;charset=utf-8",
data: { a: "testing" },
dataType: "json",
success: function(data) {
//<ul>
//<li>C#</li>
//<li>MVC</li>
},
error: function () { alert('error....'); }
});
});
</script>
How can I do it?
Succes:function(data) {//}here data return list.I'd like display this list as<ul><li></li></ul>