Click here to Skip to main content
15,887,434 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi Guys I got this error on my MVC 4 project "Specified cast is not valid." I'm new on MVC any help will be highly appreciated. Thanks in advance

What I have tried:

C#
public IEnumerable<selectlistitem> ResourceSelectList()
        {

     
            return
                GetResources().AsEnumerable().Select(u => new SelectListItem
              {
              Value = Convert.ToString(u.Field<int>("id")),
              Text = u.Field<string>("name")
                                                              });
        }
Posted
Updated 3-May-17 1:50am
v3

1 solution

Hello,

your code probably fails on this: u.Field<int>("id").
Debug your code to find what actual type is behind this "id" field.

Hope this helps.
 
Share this answer
 
Comments
Member 12390137 3-May-17 7:55am    
yes it's fails there, is a int type not sure how to solve it.Please Help
jimmson 3-May-17 7:58am    
I don't have an access to your data, so I really can't do that for you. Look at your data, find what's "id" type.
Member 12390137 3-May-17 8:28am    
There problem is between this two web.config. the first one is running smooth the second one it gives me an error when i'm connection on my server.


1. this one is working when i'm using it
<add name="DBName" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\DBName.mdf;Integrated Security=True;User Instance=False" providerName="System.Data.SqlClient" />

2. when I replace the above with the below I got Error that says"Specified cast is not valid"

<add name="DBName" connectionString="Data Source=ServerName;Initial Catalog=DBName;User ID=Username;Password=Password;Connection Timeout=120" providerName="System.Data.SqlClient" />

what's wrong please Help if you have any ideas
jimmson 3-May-17 8:36am    
Then look into these two databases on your data to see what are the differences. This isn't something anybody from internet could do for you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900