Questions tagged [viewbag]

ViewBag is a dynamic type object in the ASP.NET MVC framework that can be used to send miscellaneous data from the controller to the view.

ViewBag is a member of the ControllerBase class in the ASP.NET MVC framework. It's a dynamic type object that can be used to send miscellaneous data from the controller to the view. Its type is dynamic.

718 questions
0
votes
2 answers

How to check ViewBag's property in a cshtml page?

I am working on MVC application and I need to check ViewBag value on cshtml page, how can I do that? on Controller.cs: Viewbag.Mode= "EDIT"; I need to check the value from Viewbag.Mode if it is EDIT show alert as EDIT I am writing this conditional…
Neo
  • 15,491
  • 59
  • 215
  • 405
0
votes
1 answer

Template for ViewBag

I want to create a template to format some ViewBags. Up to now, I had only the case of property of of a class, which I could easily modify with [UIHint("MYTemplate")] public virtual float Foo { get; set; } Every selction of the property will…
Niklas S.
  • 329
  • 4
  • 16
0
votes
1 answer

There is no ViewData item of type 'IEnumerable' that has the key 'aboutcar.Doors'

In controller: ViewBag.Doors = new SelectList(new[] { new {ID = 1, Name="1-Door"}, new {ID = 2,Name="2-Doors"}, …
Ali Shahzad
  • 5,163
  • 7
  • 36
  • 64
0
votes
1 answer

How to compare data in ViewBags in a loop?

I'm trying to compare datas from two different ViewBags which contain each of them a list of objects and if two objects are the same I would like to display a checkbox checked and if not, a checkbox not checked. I've tried that: @for (int i = 0; i…
Hubert Solecki
  • 2,611
  • 5
  • 31
  • 63
0
votes
1 answer

How pass int list from action to view, then from view to method in mvc 4?

In MVC4 application in Create(post) action I want to pass int type list to view if error occur. And then, from there to pass it to other method in same controller with ajax post. So, TempData, ViewData and ViewBag don't help me. public ActionResult…
Jeyhun Rahimov
  • 3,769
  • 6
  • 47
  • 90
0
votes
3 answers

MVC update view during computation

In my controller I need to make some operations that may require a long time, so I'd like to update the view at the end of each step. I am a beginner in MVC, and according to what I know every time I want to update the view from the controller I…
user1540107
0
votes
2 answers

Certain ViewBag data accessible in _Layout.cshtml but not in View?

In my _Layout.cshtml, I store some session data in the ViewBag, like so: if (Session["SiteSession"] != null) { SiteSession siteSession = (SiteSession)Session["SiteSession"]; ViewBag.SiteSession = siteSession; } and it's been working great…
keeehlan
  • 7,874
  • 16
  • 56
  • 104
0
votes
2 answers

MVC: Displaying table data not working as expected

I have this table in database: I'm trying to display the the values (ModuleID and DateEntered) in the browser as table. I'm using viewbag to pass the value to my view, which is not quite the right way as I get just one row right now. What I'm doing…
Cybercop
  • 8,475
  • 21
  • 75
  • 135
0
votes
1 answer

Can't use @ViewBag inside @Html.textbox?

I want to set the value of a text box to a ViewBag item. Why doesn't the code below work? @Html.TextBox("UName", @ViewBag.UName)
Aparan
  • 1,263
  • 3
  • 12
  • 17
0
votes
2 answers

How to use a @Html.DropDownList with ViewBag?

I'm working with MVC4. I've added the paging, sorting and filtering functions in an Index page.As a result, I have to add a viewbag parameter to the filtering DropdownList to keep the filtering string. Here comes an example of a textbox with a…
user2423801
  • 41
  • 1
  • 2
  • 4
0
votes
1 answer

Dynamic Referring URL in ViewBag or ViewModel?

I am working on a wizard like section of an ASP.Net MVC website that allows the user to post data and redirect to the next page in either a forward or backwards direction. That is if the user clicks next it saves and goes to the next page. If they…
Louise Eggleton
  • 969
  • 2
  • 15
  • 27
0
votes
1 answer

How to search ViewBag Json string

I would like to access ViewBag data from within client side code. This is what I've tried in my controller: ViewBag.Tasks = new JavaScriptSerializer().Serialize(tasks); In my view I would then put this in a hidden field so that it available client…
Amanda
  • 159
  • 1
  • 3
  • 16
0
votes
1 answer

How to conditionally group or not group KendoUI grid based on Viewbag value

I need to pass a column name or the value 'none' to my kendo grid to conditionally group it based on the value of a Viewbag element. When I pass the column name in it groups as expected. My issue is to not do grouping if the value 'none' is passed…
MikeD
  • 741
  • 5
  • 20
  • 38
0
votes
2 answers

How to create a DropDownList from an encapsulated property from a dynamically created ViewBag?

Note: Variables names were changed to keep my code's purpose anonymous. Task: Create a SelectList that will show what was chosen (if anything was chosen), and will generate a list to choose from. ViewBag Declaration / Definition in the CarShow…
0
votes
1 answer

Pass ViewBag to _Layout in MVC?

In my Search controller I have: public JsonResult Search(string term) { var termLower=term.ToLower(); var pictures=_PictureRepo.GetAll(); var productsWereSeached = _ProductRepo.GetAll().Where(x =>…
Vlado Pandžić
  • 4,879
  • 8
  • 44
  • 75