It is evident looking at your code that you are Type casting an Integer Value to string and hence the error. Make sure to convert the String to Integer before doing any operation,
let says your string varialbe name is "myValue" then you must do Convert.ToInt32(myvalue);
A fundamental rule in technology says whatever can be done will be done
One of the properties on the left of an "=" will be an int and one on the right will be a string. The solution is to convert that to an int when you assign it. However we don't know what your types are, you'll have to check them yousrelf. You need to
learn how to debug your code properly as this is a fairly simple thing to do, but we can't do it with the information you are supplying.
maya_kadekar
Member
1 Points
27 Posts
Query
Jan 30, 2013 08:39 AM|LINK
Error:
Unable to cast object of type 'System.Int32' to type 'System.String'.
We are working on asp.net mvc3 and facing above error in our project. So please reply solution as soon as possible.
goel.ankit
Contributor
2531 Points
513 Posts
Re: Query
Jan 30, 2013 08:50 AM|LINK
I do not see a reason of the error. Please share your code.
Ankit
(Please select 'Mark as Answer' if my response has helped you.)
sandeepsacha...
Member
68 Points
29 Posts
Re: Query
Jan 30, 2013 09:19 AM|LINK
Can you share the code snipet?
Website: www.sandeepsachan.com
ankit.sri
Contributor
2042 Points
410 Posts
Re: Query
Jan 30, 2013 09:26 AM|LINK
It is evident looking at your code that you are Type casting an Integer Value to string and hence the error. Make sure to convert the String to Integer before doing any operation,
let says your string varialbe name is "myValue" then you must do Convert.ToInt32(myvalue);
maya_kadekar
Member
1 Points
27 Posts
Re: Query
Jan 30, 2013 09:34 AM|LINK
public ActionResult Create(ClientRegistration client,FormCollection frmclientcollection,HttpPostedFileBase file)
{
DateTime registrationDate = Convert.ToDateTime(frmclientcollection["regdate"].ToString());
DateTime ContractPeriod = Convert.ToDateTime(frmclientcollection["ContractPeriod"].ToString());
var clientModel = new ClientRegistration()
{
companyname = client.companyname,
companyprofile = client.companyprofile,
companyaddress= client.companyaddress,
country = client.country,
state = client.state,
pincode =client.pincode,
contactno =client.contactno,
email =client.email ,
website= client.website,
pointofcontact=client.pointofcontact,
designation =client.designation,
dateofregistration = registrationDate,
noofvacancies = client.noofvacancies,
contractperiod = ContractPeriod,
industry = client.industry,
jobcategory = client.jobcategory
};
_clientService.CreateClient(clientModel);
return RedirectToAction("List", "Client");
}
jp.lima
Member
186 Points
51 Posts
Re: Query
Jan 30, 2013 10:07 AM|LINK
maya_kadekar
Member
1 Points
27 Posts
Re: Query
Jan 30, 2013 10:27 AM|LINK
why u have taken bool datatype?
jp.lima
Member
186 Points
51 Posts
Re: Query
Jan 30, 2013 10:31 AM|LINK
The bool is for you to check if you can convert the string to date time. The date is in the variable prior to the bool if TryParse works.
maya_kadekar
Member
1 Points
27 Posts
Re: Query
Jan 30, 2013 10:42 AM|LINK
Any other datatype instead of bool because bool is not working. Its giving error
AidyF
Star
9204 Points
1570 Posts
Re: Query
Jan 30, 2013 10:47 AM|LINK
One of the properties on the left of an "=" will be an int and one on the right will be a string. The solution is to convert that to an int when you assign it. However we don't know what your types are, you'll have to check them yousrelf. You need to learn how to debug your code properly as this is a fairly simple thing to do, but we can't do it with the information you are supplying.