In my MVC Application "TwentyFifth", Model is :
public class Student {
public string StudentName { get; set; }
public int StudentID { get; set; }
public string FatherName { get; set; }
}
A Method is Support-Class in Same Project is :
public void EditSupport(int id, Student std2)
{
SqlConnection Con = new SqlConnection("Data Source=my;Initial Catalog=DB;Integrated Security=True");
SqlCommand Com = new SqlCommand("update StudentT set StudentName='"+ std2.StudentName + "', FatherName='" + std2.FatherName + "' where StudentID=" + id + "", Con);
Con.Open();
Com.ExecuteNonQuery();
}
And finally, Controller goes like :
[HttpPost]
[ActionName("Edit")]
public ActionResult Edit_Post(int id, FormCollection formCollector)
{
Student std = new Student();
std.StudentID = id;
std.StudentName = formCollector["StudentName"].ToString();
std.FatherName = formCollector["FatherName"].ToString();
BussinessNdataLayer bl = new BussinessNdataLayer();
bl.EditSupport(id, std);
return RedirectToAction("Index");
}
Question : Why there is a Format Exception when I change Controller with ->
std.StudentID = Convert.ToInt32(formCollector["StudentID"]);
Note : at a break point I found string value in std.StudentID but with a Comma(,) Thanks for your reply.