嗨,有人能帮我吗…我对C和MVC很陌生
模型是:

public class CatagoryModel {
    public int Id { get; set; }
    public string  CName { get; set; }
}

控制器是:
   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);
      }

这样的景色
@model MvcApplication1.Models.CatagoryModel
<ul>
@foreach(var k in Model){
   <li>@k.Id</li>
    <li>@k.CName</li>

}

我不知道出了什么问题…
它在呈现视图时显示错误。

最佳答案

好吧,如果您的模型是Enumerable,那么在您的视图中,它必须是可枚举的!

@model IEnumerable<MvcApplication1.Models.CatagoryModel>

08-03 23:14