Witam wszystkich może ktoś mi pomoże ... Im bardzo nowe do C# i MVCJak obsługiwać listy, zbieranie lub IEnumerable w widoku
model jest:
public class CatagoryModel {
public int Id { get; set; }
public string CName { get; set; }
}
Controller jest:
public ActionResult catagory() {
var c = new CatagoryModel();
var URL="";
HttpWebRequest req = WebRequest.Create(URL)
as HttpWebRequest;
string result = null;
using (HttpWebResponse resp = req.GetResponse()
as HttpWebResponse)
{
StreamReader reader =
new StreamReader(resp.GetResponseStream());
result = reader.ReadToEnd();
}
var categories = JsonConvert.DeserializeObject<List<CatagoryModel>>(result);
return View(categories);
}
Zobacz tak
@model MvcApplication1.Models.CatagoryModel
<ul>
@foreach(var k in Model){
<li>@k.Id</li>
<li>@k.CName</li>
}
i nie wiem, co poszło nie tak ...
To pokazuje błąd podczas renderowania widoku ..
Chciałbym również polecić [tworząc ViewModel specyficzne dla poglądu, że kapsułkuje potrzeb Państwa zdanie i jest rozszerzalny] (http : //msdn.microsoft.com/en-us/vs2010trainingcourse_aspnetmvc3fundamentals_topic7.aspx). –