2011년 12월 5일 월요일

ViewBag

controller에서 view로 데이터를 전송하느 방법중 하나는 ViewBag 오브젝트를 이용하는 것이다. 컨트롤러 베이스 클래스의 멤버인 ViewBag을 이용해 전달하는 법



 public ViewResult Index() {
           ViewBag.Message = "Test Message";
            return View();
 }

@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <title>Index</title>
</head>
<body>
    <div>
        @ViewBag.Message,Hello, world (from the view)
        @Html.ActionLink("RSVP Now", "RsvpForm")
    </div>
</body>
</html>

댓글 없음:

댓글 쓰기

팔로어