Am i trying to create the functionality for sign up page but something is going wrong...am not getting any hit..can any one help me what's going wrong in my code...
Controller:
[HttpPost]
public ActionResult Index(Users model)
{
using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["DatContext"].ConnectionString))
{
var cmd = new SqlCommand("USp_InsertUsers", con);// Give The command to SqlCommand
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@UserName", SqlDbType.VarChar)).Value = model.UserName.Trim();
cmd.Parameters.Add(new SqlParameter("@Email", SqlDbType.VarChar)).Value = model.Email.Trim();
cmd.Parameters.Add(new SqlParameter("@Password", SqlDbType.VarChar)).Value = model.Password;
try
{
if (con.State != ConnectionState.Open)
con.Open();
cmd.ExecuteNonQuery();
ViewBag.message = "Account Created";
return View();
}
finally
{
if (con.State != ConnectionState.Closed)
con.Close();
}
}
return View("Index");
}
View:
User Signup
@using (Html.BeginForm("Index", "Register", FormMethod.Post, new { id = "registerForm" }))
{
@Html.ValidationMessageFor(model => model.UserName)
@Html.ValidationMessageFor(model => model.Email)
@Html.ValidationMessageFor(model => model.Password)
}
3 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Munesh SharmaPosted Jun 10, 2015, 3:22 AM
Upendra Pratap ShahiPosted Jun 9, 2015, 3:57 AM
Saineshwar BageriPosted Jun 9, 2015, 2:31 AM