Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • ViewData in Asp.Net Mvc application

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 65
    Comment on it

    ViewData in Asp.Net Mvc application

    • ViewData is one of the property of ControllerBase class.
    • It is described as dictionary object whichis derived from ViewDataDictionary class.Thse syntax of it is as follows:-
    public ViewDataDictionary ViewData { get; set; }
    • Passing and maintaing data from controller to corresponding view is done using ViewData.
    • Their only aim is to provide communication between controller and corresponding view therefore ViewData life is short i.e within current request and it's value becomes null whenever redirection occur.
    • Type casting for complex data type ViewData value is required.

    Example of ViewData:

    Controller with Index action have ViewData:-

    public ActionResult Index()
    {
    ViewData["Name"] = "Suraj rana";
    return View();
    } 

    ViewData is used in a view. With respect to Index action a view is called and data between them is maintained by ViewData:-

    @ViewData["Name"]

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: