[英]How to pass querystring value in @Url.Action in MVC4
我在_Layout.cshtml頁面中傳遞了querystring值
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
<li>@Html.ActionLink("Shopping", "Index1", new { controller = "Shopping", UserID = "Admin" })</li>
如何在“ View 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>
我沒有在控制器中獲取querystring值
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();
}
您需要一個名為id的參數作為刪除操作方法
Public ActionResult Delete(string id){
//delete the Request.QueryString line
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.