This project is read-only.

Error in forum post

Topics: Developer Forum, Project Management Forum
Jul 15, 2009 at 1:23 PM

On the example site if you click on a forum post, you get the following error:

Specified cast is not valid

 

Also the code:   

<% var userVote = (int)ViewData["userVote"]; %>

 

is using "magic strings" instead of a strongly typed model

 

Jul 23, 2009 at 7:01 AM

line 90 in ForumController.cs
Change

ViewData["userVote"] = vote == null ? (short)0 : vote.Direction;

as

  ViewData["userVote"] = vote == null ? (int)0 : vote.Direction;


Don't understand why cast to short?
Jul 24, 2009 at 1:45 AM

No matter how hard you try you will need to use the magic string here or there. The reason is you are going to get lazy and don't want to me a custom model for every single view because it just doesn't make sense. If I have a custoer model and a product model, do I make a custom model to include both so I can pass it into my customer product review page? Its not optimal but it makes sense.

Jul 24, 2009 at 2:04 AM

<< "No matter how hard you try you will need to use the magic string here or there. The reason is you are going to get lazy >>

 

This just isn't true.  For one some people do believe in having a custom viewmodel for every view.  Personally I don't believe that is necessary, however it is precisely because of errors like the above that you should not be lazy.  Creating a new custom viewmodel is not a big deal.  Simply add properties to the viewmodel to include the Product and the Customer.

Laziness leads to brittle and hard-to understand code.