1

i have used the following code in my view and made the model it is giving the error in (IEnumerable<ITClassifieds.Models.Resume>)

<%--  
    foreach (ITClassifieds.Models.Resume  c in (IEnumerable<ITClassifieds.Models.Resume>)ViewData["getresume"])
    { %>
        <input type="radio" name="resumeID" value="<%=c.ResumeID %>" checked="checked"/>Yes
        <input type="radio" name="resumeID" value="0"/>No
  <%} %>
Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448
iProgrammer
  • 3,099
  • 3
  • 33
  • 59
  • 2
    Are you sure that is an enumerable set of `ITClassifieds.Models.Resume` you are trying to loop through? – BoltClock May 25 '11 at 08:37
  • 1
    @BoltClock, good point. That's always the problem when you use `ViewData`. No Intellisense, you never know the correct type, you should perform ugly casts in the view and as a consequence to this errors are more difficult to find and reveal at runtime. Those are some of the reasons why I always avoid using `ViewData` in favor of strongly typed views and view models. – Darin Dimitrov May 25 '11 at 08:50
  • So whats the solution for this? how can I recognize error? – iProgrammer May 25 '11 at 09:28
  • 1
    using the debugger, set a break point in the `foreach` statement and verify the contents of your `ViewData` using "Add Watch" or "Quick Watch" or the Interactive Console. – Daren Thomas May 25 '11 at 09:47
  • But it is not running because of error.. – iProgrammer May 25 '11 at 09:49

1 Answers1

0
  1. Go back to where you are setting getresume in your controller.. confirm that it is setting to what you are expecting.

  2. Post the full error you are receiving.

Or

  1. Create yourself a viewmodel and use that instead. Dynamics are great and I use them a fair amount but when it comes to views I always go with strongly typed.

http://geekswithblogs.net/michelotti/archive/2009/10/25/asp.net-mvc-view-model-patterns.aspx - Talks about a few different ways to do your viewmodels.

Another interesting link would be -> ViewModel Best Practices

Community
  • 1
  • 1
David McLean
  • 1,462
  • 1
  • 12
  • 27