2
我通過在_Layout.cshtml頁面查詢字符串值如何@ Url.Action通過查詢字符串值MVC4
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
<li>@Html.ActionLink("Shopping", "Index1", new { controller = "Shopping", UserID = "Admin" })</li>
如何通過在瀏覽Index1.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();
}