Resolved Is it ok To Transfer route values from controller to views with viewdata and view bag rather than ViewModel

Joined
Oct 31, 2021
Messages
13
Programming Experience
Beginner
Which is Good To Use By View bag or By ViewModel

Doing it With viewbag:
[HttpGet]
public ActionResult Edit(string searchedSiblingStudentName=null)
{
    Viewbag.SearchedStudentName= searchedSiblingStudentName;
    return View()
}
[/CODE]



Doing It With ViewModel:
        [HttpGet]
        public ActionResult Edit(string searchedSiblingStudentName=null)
        {
            var dd= new EditViewModel();
            dd.SiblingStudentName=searchedSiblingStudentName;  
            return View(dd)

        }
 
You can if you want to. Consider though that the view bag is an ExpandoObject that has slower performance than a concrete type. For places where performance does not matter, or you are still in the prototyping stage where it is now expedient to just throw things into the view bag, then have at it. A concrete type gives you speed and compile time checking.
 
Back
Top Bottom