2


I passed a querystring value in _Layout.cshtml page

 <li>@Html.ActionLink("Contact", "Contact", "Home")</li>
 <li>@Html.ActionLink("Shopping", "Index1", new { controller = "Shopping", UserID = "Admin" })</li> 


How to pass the value in the View Index1.cshtml page

 <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>

I am not getting the querystring value in my controller

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

1 Answer 1

5

You need an argument called id for your delete action method

Public ActionResult Delete(string id){
     //delete the Request.QueryString line
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.