Xyz ...

Xyz ...

  • NA
  • 6
  • 697

Edit hyperlink mvc

Feb 15 2018 5:13 AM
There is a edit hyperlink in my table, when i click on my edit hyperlink a new edit window should be open and i want to edit the particular id row and when i made some changes and click on the save button the entire row should be saved in my sql database.
 Here i am not using gridview and entity framework, i am using ado.net below is my code
 
now i want the code for edit action link
public ActionResult edit()
{
}
return View();
 
This code is for retrieving data:-
----------------------------------------
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>getdata</title>
</head>
<body style="background-color:lightgray">
<table border="1">
<tr>

<th>username</th>
<th>password</th>
<th>address</th>
<th>emailid</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>@item.username</td>
<td>@item.password</td>
<td>@item.address</td>
<td>@item.emailid</td>
<td>

@Html.ActionLink("Edit", "getdata",new { id = item.userid }) |
@Html.ActionLink("Delete", "getdata")
</td>
</tr>
}

</table>
</body>
</html>

 
 
public ActionResult getdata()
{
string conn = "Data Source=localhost;Integrated Security=true;Initial Catalog=employee";
SqlConnection cn = new SqlConnection();
cn.ConnectionString = conn;
SqlCommand cmd = new SqlCommand("select*from emp");
cmd.Connection = cn;
SqlDataAdapter adp = new SqlDataAdapter();
adp.SelectCommand = cmd;
DataSet ds = new DataSet();
DataTable dt = new DataTable();
DataRow dr;
adp.Fill(ds);
dt = ds.Tables[0];
List<Class1> c = new List<Class1>();
for (int i = 0; i < dt.Rows.Count; i++)
{
dr = dt.Rows[i];
c.Add(new Class1()
{
// userid = Convert.ToDecimal(dr["userid"]),
username = Convert.ToString(dr["username"]),
password = Convert.ToString(dr["password"]),
address = Convert.ToString(dr["address"]),
emailid = Convert.ToString(dr["emailid"])
});
}
return View(c);
 
 
This code is for sign up page:-
--------------------------------------
 
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script type="text/javascript">


function checkform(form) {
if (form.userid.value == "") {
alert("invalid userid");
form.userid.focus();
return false;
}
if (form.username.value == "") {
alert("invalid username");
form.username.focus();
return false;
}
if (form.password.value == "") {
alert("invalid username");
form.password.focus();
return false;
}
if (form.address.value == "") {
alert("invalid username");
form.address.focus();
return false;
}
if (form.emailid.value == "") {
alert("invalid username");
form.emailid.focus();
return false;
}
if (form.username.value == "") {
alert("invalid username");
form.username.focus();
return false;
}
alert("saved");
};


</script>
</head>
<body style="background-color:lightgray">
<form action="/Home/signup/" method="post" onsubmit="return checkform(this)">
userid:<input type="text" name="userid" /><br /><br />
username: <input type="text" name="username" id="t1" /><br /><br />
password: <input type="text" name="password" /><br /><br />
address: <input type="text" name="address" /><br /><br />
emailid: <input type="text" name="emailid" /><br /><br />
<input type="submit" id="btn1" value="signup" />

</form>
</body>
</html> 
 
 [HttpGet]
public ActionResult signup()
{
return View();
}
[HttpPost]
public ActionResult signup(string userid,string username, string password, string address, string emailid)
{
Class1 c1 = new Class1();
string connn = "Data Source=localhost;Integrated Security=yes; Initial Catalog=employee;";
SqlConnection cn = new SqlConnection();
cn.ConnectionString = connn;
SqlCommand cmd = new SqlCommand("pro", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "pro";
cmd.Parameters.AddWithValue("@userid", userid);
cmd.Parameters.AddWithValue("@username", username);
cmd.Parameters.AddWithValue("@password", password);
cmd.Parameters.AddWithValue("@address", address);
cmd.Parameters.AddWithValue("@emailid", emailid);

cn.Open();
cmd.ExecuteNonQuery();

cn.Close();

return View();

Answers (1)