2011-10-04 3 views
0

블로그가 있습니다. 메인 페이지에는 주제 목록이 있습니다. 사용자가 항목을 삭제할 수있게 해주는 단추를 만들고 싶습니다. 목록의 모든 항목 ID를 알고 데이터베이스의 키 필드입니다.어떻게 프로 시저에 매개 변수를 전달할 수 있습니까?

조회수/홈/색인 :

@{ 
    if (ViewBag.userIsModerator) 
     using (Html.BeginForm("DeleteTopic", "Home", new { topicId = item.ID })) 
     { 
      <input type = "submit" value = "Delete topic" /> 
     } 
    } 

다음 절차는 제출에 클릭 한 후 시작된다.

컨트롤러/HomeController : 새로운 는 {위해 topicId = item.ID} 오류의 원천이기 때문에

[HttpPost] 
public ActionResult DeleteTopic(int topicId) 
{ 
    db.DeleteTopic(topicId); 
    return RedirectToAction("Index", "Home"); 
} 

내 문제는, 컨트롤러에 주제의 ID를 전달하는 것입니다. 아무도, 없이이 문제에 도달하는 방법을 알고 있습니까 새로운 {topicId = item.ID}?

답변

0

내부에서 숨겨진 필드를 사용할 수 있습니다.

@using (Html.BeginForm()) 
{ 
    <input type="hidden" name="topicId" value="5" /> 
    ... 
} 
관련 문제