Able to access Database without opening connection, using Dapper

So I have the following piece of code that is showing a strange behavior or I am missing some point here: public async Task<IEnumerable<MyData>> GetMyData() { MySqlConnection conn; IEnumerable<MyData> list; string querystring = "SELECT * FROM tbl_mydata;"; using (conn = new MySqlConnection(mydbconnectionString)) { //conn.Open(); ConnectionState check1 = conn.State; list = await conn.QueryAsync<MyData>(querystring, commandType: CommandType.Text); ConnectionState … Read more

Redirect back to Previous Page without losing original data

I have trouble preserving the original data by redirecting the same page when my custom error handling is executed in the controller.
Assume that I have a web page call Create.cshtml.
In that create webpage, I have a few form control which require the user to enter class code but the class code cannot be duplicated.
Assume that the user entered a class code that is existed in the system, my system should redirect back to Create.cshtml and pass error message (E.g. ViewBag.error = “Class Code duplicated”) and simulatenously .
But my current implementation does not revert back the original content/data after redirect.