_Layout.cshtmlページでクエリ文字列値を渡しました
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
<li>@Html.ActionLink("Shopping", "Index1", new { controller = "Shopping", UserID = "Admin" })</li>
ViewIndex1.cshtmlページで値を渡す方法
<a href="@Url.Action("Delete","Shopping", new { id = Request.QueryString["UserID"] })">
<img alt="removeitem" style="vertical-align: middle;" height="17px" src="~/Images/remove.png" title="remove" />
</a>
コントローラでクエリ文字列の値を取得していません
public ActionResult Delete()
{
string id = Request.QueryString["UserID"];
int records = DeleteItem(id);
if (records > 0)
{
return RedirectToAction("Index", "Shopping");
}
else
{
ModelState.AddModelError("", "Can Not Delete");
return View("Index");
}
}
public int DeleteItem(string id)
{
con.Open();
SqlCommand cmd = new SqlCommand("delete from Cpecial_Shopping_Cart_tbl where [User ID]='" + id + "'", con);
return cmd.ExecuteNonQuery();
}