Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Hi all can anyone help me ... Im very new to c# and mvc

The Model is:

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

The Controller is:

   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);
      }

The View like this

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

}

And i dont know what went wrong ...
It shows an error while rendering the view ..

share|improve this question

2 Answers

Well, if your model is Enumerable, in your view, it must be enumerable !

@model IEnumerable<MvcApplication1.Models.CatagoryModel>
share|improve this answer

Your Model is a list of CategoryModel, not a single CategoryModel:

@model IEnumerable<MvcApplication1.Models.CatagoryModel>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.