2014-12-02 13 views
1

MVC를 처음 사용함. 나는 ViewData, ViewBag 및 TempData를 사용하여 객체를 전달해야하며 ViewData 및 ViewBag의 성능에 차이가 있는지 알고 싶습니다. performan 위해 아래 링크Whats ViewBag 및 View Data의 성능 차이 및 사용시기

+4

[ViewBag, ViewData 및 TempData] 가능한 중복 (http://stackoverflow.com/questions/7993263/viewbag-viewdata-and-tempdata) –

답변

0

데이터보기 : 보기 데이터보기 데이터 사전 클래스에서 파생 된 사전 개체입니다. 뷰 데이터는 Controller Base 클래스의 속성입니다. 뷰 데이터는 컨트롤러에서 해당 뷰로 데이터를 전달하는 데 사용됩니다. 사용법 :

공공 ActionResult 지수()

{ 

    ViewData.Name = "Tony Boss"; 
    return View(); 

} 

보기 가방 보기 가방 새로운 동적 C# 4.0의 기능을 활용하는 동적 속성입니다. 기본적으로 뷰 데이터 주위의 래퍼이며 컨트롤러에서 해당 뷰로 데이터를 전달하는 데 사용됩니다. View Bag은 Controller Base 클래스의 속성입니다.

사용법 :

공공 ActionResult 지수()

{ 

    ViewBag.Name = "Tony Boss"; 
    return View(); 

} 

온도 데이터 : 온도 데이터는 온도 데이터 사전 클래스에서 파생 세션 온도 데이터는 짧은 삶에 저장되어있는 사전 개체입니다 Controller Base 클래스의 속성입니다. 임시 데이터는 현재 요청에서 후속 요청 (한 페이지에서 다른 페이지로 리디렉션 됨)으로 데이터를 전달하는 데 사용됩니다.

0

을 ViewData

ViewData is used to pass data from controller to view 
It is derived from ViewDataDictionary class 
It is available for the current request only 
Requires typecasting for complex data type and checks for null values to avoid error 
If redirection occurs, then its value becomes null 

ViewBag

ViewBag is also used to pass data from the controller to the respective view 
ViewBag is a dynamic property that takes advantage of the new dynamic features in C# 4.0 
It is also available for the current request only 
If redirection occurs, then its value becomes null 
Doesn’t require typecasting for complex data type 

TempData

TempData is derived from TempDataDictionary class 
TempData is used to pass data from the current request to the next request 
It keeps the information for the time of an HTTP Request. This means only from one page to another. It helps to maintain the data when we move from one controller to another controller or from one action to another action 
It requires typecasting for complex data type and checks for null values to avoid error. Generally, it is used to store only one time messages like the error messages and validation messages 
참조

CE 체크

http://spiritofdev.blogspot.in/2011/12/performance-of-c-40-dynamic-vs.html

+0

답변을 주셔서 감사합니다. 나는 일반적인 생각을 가지고있다. –