Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 06, 2013 09:20 AM by goel.ankit
Jan 30, 2013 08:39 AM|LINK
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.
Jan 30, 2013 08:50 AM|LINK
I do not see a reason of the error. Please share your code.
Jan 30, 2013 09:19 AM|LINK
Can you share the code snipet?
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);
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,
country = client.country,
state = client.state,
email =client.email ,
dateofregistration = registrationDate,
noofvacancies = client.noofvacancies,
contractperiod = ContractPeriod,
industry = client.industry,
jobcategory = client.jobcategory
return RedirectToAction("List", "Client");
Jan 30, 2013 10:07 AM|LINK
bool canConvert = DateTime.TryParse(frmclientcollection["regdate"].ToString(), out regDate);
bool canConvert = DateTime.TryParse(frmclientcollection["ContractPeriod"].ToString(), out contractPeriod);
Jan 30, 2013 10:27 AM|LINK
why u have taken bool datatype?
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.
Jan 30, 2013 10:42 AM|LINK
Any other datatype instead of bool because bool is not working. Its giving error
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.