에 쿼리 문자열 반환 나는FormMethod.Post이 MVC4
<li>@Html.ActionLink("Shopping", "Index1", new { controller = "Shopping", UserID = "Admin1" })</li>
내가에서 텍스트 상자
@using (Html.BeginForm("Update", "Shopping", new { id = Request.QueryString["UserID"] }, FormMethod.Post, new { id = "myForm" }))
{
@Html.Hidden("id", @Request.QueryString["UserID"] as string)
@Html.Hidden("productid", item.ProductID as string)
@Html.TextBox("qty", item.Quantity)
@Html.Hidden("unitrate", item.Rate)
<input type="submit" value="Update" />
}
에서 값을 업데이트하는 업데이트보기를 _Layout.cshtml 페이지 내 쿼리 문자열을 통과 처음 게시물, 난이 같은 URL을 얻을
http://localhost:61110/Shopping/Index1?UserID=Admin1
는 그러나 두 번째, 포스트 후에 나는이 양식을 게시 할 때이
http://localhost:61110/Shopping/Index1
같은 URL이 어떻게 항상 쿼리 문자열 값을 얻을 수.
나는이 mvc3: html.beginform search returning empty querystring
을 시도하지만 두 번째 포스트
어떤 제안에 쿼리 문자열을 얻을 couldnt한다.
편집 : 업데이트 작업 코드
[HttpPost]
public ActionResult Update(string id, string productid, int qty, decimal unitrate)
{
if (ModelState.IsValid)
{
int _records = UpdatePrice(id,productid,qty,unitrate);
if (_records > 0)
{
return RedirectToAction("Index1", "Shopping",new { id = Request.QueryString["UserID"] });
}
else
{
ModelState.AddModelError("","Can Not Update");
}
}
return View("Index1");
}
public int UpdatePrice(string id,string productid,int qty,decimal unitrate)
{
con.Open();
var total = qty * unitrate;
SqlCommand cmd = new SqlCommand("Update [Table_name] Set Quantity='" + qty + "',Price='" + total + "' where [User ID]='" + id + "' and [Product ID]='" + productid + "'", con);
cmd.Parameters.AddWithValue("@total", total);
return cmd.ExecuteNonQuery();
}
'업데이트'액션 코드를 게시 할 수 있습니까? 게시물의 URL이 어떻게되어야합니까? 'http : // localhost : 61110/Shopping/Index1? UserID = Admin1'과 같은가? 그래서'UserID = Admin1' 부분을 유지하고 싶습니까? – nemesv
쿼리 문자열 http : // localhost : 61110/Shopping/Index1? UserID = Admin1을 사용하여 게시 할 URL이 필요합니다. – kk1076