2


我在 _Layout.cshtml 页面中传递了一个查询字符串值

 <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();
} 
4

1 回答 1

5

您的删除操作方法需要一个名为 id 的参数

Public ActionResult Delete(string id){
     //delete the Request.QueryString line
}
于 2012-10-17T06:52:31.413 回答