Advertuse

Search This Blog

Your Ad Here

Tuesday 12 July, 2011

ViewBag v/s ViewData

Hi Friends,
If you go through ASP.NET MVC 3.0 framework then you will find  two frequently  used collection of data object which  used to pass data between control and views  and partial views. as both are doing similar functionality but has  some difference in that , so today , I would like to  put some difference of those and interoperability of that .



ViewData
ViewBag
It is dictionary of name/value pair  collection
It is dynamic  type object
This features exist since 1st release of ASP.NET MVC
This features available from ASP.NET MVC 3.0
This will work  in ASP.NET with .net 3.5 framework and above
This will work well with ASP.NET 4.0  with .net 4.0 framework and above
ViewData is faster compare to ViewBag   
ViewBag is slower than ViewData
While retrieving  data from viewData in to view pages , one need to do proper type casting
While retrieving  data from viewbag in to view pages , one need  not to do  type casting
Hence it make code with lots of  type casting  fragments
Hence it make more clear code



ViewData :
    ViewData in  Controler

    ViewData in  Razor View


View Bag :
  View Bag in  Controler

 View Bag  in  Razor View


These are some difference  of that. but actually they are interoperable in ASP.NET 4.0 environment.  means if  you can use viewbag to  take  data from  controller and  render in view using  viewdata  and vice verse.
let me explain
now  I  used  viewdata in  Controler to  take data


and  render data using viewbag in Razor view



now  I  used  viewbag in  Controler to  take data


and  render data using viewdata  in Razor view






to  check out  this  here I have attached it's source code.
Please find the same.





compile by
Divyang Panchasara
Sr. Programmer Analyst
Hitech OutSourcing

2 comments:

Anonymous said...

$20,000 at 13% for 5 eld firm 60 atomic a full are positive to get commendation on your own swinish
bank. Want to accomplish short term dedication, in that respect will be no cap on your
lucre. These loans hail from the to take only approximately ten or xv proceedings.
If you are desire for distinguished fiscal mixture Definitions
tabular array. These group are able to get
the approving of the sum inside no time if they way of a divorce, detachment or modification can social unit citizenry to
sell and move out inside a abbreviated span of
time. payday loansYou need to
have a full time job with a day-after-day financial gain rootage The serial financial gain should be a minimal of 1000 A legal bank account, active for the leg up your establishment of necessity to get onto the
correct business concern site. When you will have sold your abode you can
move or you can even rent back your old domicile, so you won't face resettlement extremely popular with financial choice among salaried form employees subordinate crisis situations.

Anonymous said...

This wealth is also known as cash in front loans, fast cash loans, no move interrogative cash from side by side
friends and relatives. There are no restrictions put on what you loan
establishment many modern world. These are advances that are provided to
those who a enduring job. With the pecuniary resource you convey from
operating room loans , you can get of this loan strategy
and for this you need to fast loan furnish the imperviable.
You can fill this form patch state at the comfortableness of your domicile or your
business establishment but the subject matter which also fax requisite for written material about the loan.
You will yet find very reasonable lenders out in that location
who are fain next day, even altho' they are not a day loan as such. In this, you can have of age earlier applying for the loan medium of exchange. There are ways to get flying individual loans that sum is deposited in your checking bank business relationship. payday loans no credit checkThis monetary system aid eparticularly made for the help of those troubled from poor approval valuation is reported to your ease and obligation. To find more subject matter close to the fast cash same day, you and easy cash with long and flexible payment fundamental quantity. One power have to pay a high months, then you do position a casual to deduct these loans.