viewbag Questions

3

I am trying to access the ViewBag data in my view as below: <span class="small">@ViewBag.BreadCrumb</span> I am sending that ViewBag data from code like: ViewBag.BreadCrumb = topic...
Morello asked 27/2, 2014 at 7:36

3

Solved

I've set a value into Viewbag.message in my default HomeController and successfully display it in my Shared/_Layout.cshtml. After that I added another TestController and in the TestController vie...
Quarterdeck asked 28/8, 2013 at 4:8

10

Solved

I am using MVC 3 with the Razor view engine. I want to set some values in the ViewBag inside a Partial View and want retrieve those values in my _Layout.cshtml. For example, when you setup a defaul...
Faison asked 11/2, 2011 at 21:3

8

Solved

By default the new project template for ASP.NET MVC 3 adds the following to the default layout (masterpage in razor): <title>@ViewBag.Title</title> The view must then contain the fol...
Magistery asked 8/8, 2011 at 8:48

5

Solved

OK, quite new to ASP.Net MVC, so I'm sorry if this is a silly question, but how do I go about showing the values of a ViewBag as HTML. For Example, if ViewBag.SomeMessage contains the following tex...
Nutlet asked 2/9, 2011 at 15:32

1

Solved

I'm trying to access the elements of a list stored in ViewBag as follows: function equipamentoTemControle() { for(i = 0; i < @ViewBag.qtdEquipamentos; i++) { var contratocod = @ViewBag.Dad...
Joappa asked 9/9, 2016 at 15:11

2

Solved

I'm fairly new to MVC4, EF5 and ASP.Net, and I don't seem to be able to find a good answer anywhere. Basically, Should everything be done through the viewmodel or is it Ok to also incorporate view...
Galimatias asked 8/12, 2012 at 16:18

2

Solved

Is there any way to create and use dynamic properties for ViewBag, based on strings? Something like ViewBag.CreateProperty("MyProperty"); ViewBag.Property("MyProperty") = "Myvalue"; Thank you ...
Lustre asked 29/10, 2011 at 0:25

3

Solved

i'm currently working a list of data that i need to display in a view that represent a list and show for each item the corresponding action that can be executed, like edit them or delete them. For ...
Kingsize asked 12/4, 2012 at 13:11

3

Solved

So I have a ViewBag.Something and this data is randomly generated. In my view, I set this to a label like so @Html.LabelFor(m => m.Something, (string)ViewBag.Something). This works out well but ...
Issuable asked 12/6, 2012 at 13:26

3

Solved

What if i use too many ViewBag in MVC3 page? What extreme problems will be there if i continue use them heavily. In less words, what are the disadvantages of ViewBag and what is the alternate for i...
Kelleher asked 22/3, 2013 at 10:19

3

Solved

How do you deal with avoiding ViewBag due to its risk of error with being dynamic but also avoid having to populate a new ViewModel and pass it back to the view each time. For instance, I don't wan...
Scolex asked 22/3, 2013 at 20:53

5

This is more of a generic architectural question: I'm trying to decide if it's ok for my programmers to use "ViewBags" to pass data to views that already accept Models. My personal preferen...
Clipclop asked 12/2, 2014 at 1:42

3

When I set ViewBag.Title at the top of a Razor template, the Model.Title editor template text box is populated using the value of ViewBag.Title instead of the expected Model.Title value. Calling Ht...

1

Solved

Is there any way to clear the ViewBag? ViewBag has no setter, so it can't simply be nulled out: ViewBag = null; I also can't seem to use reflection to iterate over it and wipe out its dynamic ...
Korten asked 16/3, 2015 at 20:17

5

Solved

I have a situation where I would like to do something simular to what was done with the ASP.NET MVC 3 ViewBag object where properties are created at runtime? Or is it at compile time? Anyway I was...
Effeminize asked 26/4, 2011 at 23:46

3

Solved

i have @Html.ActionLink("Remove 1034, 1035, 1036", "RemoveSelected") Now i want to set each id from Controller for example: @Html.ActionLink(ViewBag.RemoveSelectedTitle, "RemoveSelected") //t...
Fiveandten asked 9/6, 2011 at 12:31

5

Solved

I am passing a variable ViewBag.crimeRef from my controller and am using it to display a message which works fine: @if(ViewBag.crimeRef != null) { <div class="alert alert-dismissable alert-dan...
Tavel asked 19/8, 2014 at 9:57

3

Solved

I have a list of users which I pass from my controller to my view using the view bag. Now I need to be able to pass the same list to the javascript on the page. I could reconstruct the list using a...
Mildamilde asked 8/3, 2013 at 10:15

2

Is there a Way to Create a Global ViewBag that can be used in Different Views. In my application's scenario, 1)I have used a DropDown for Company that is used into _Layout.cshtml page. 2) For th...
Nichani asked 30/4, 2014 at 6:40

2

Solved

I want to assign some ID attribute name to my Dropdown list which is using data from the ViewBag as, ViewBag.Group = new SelectList(group, "GroupId", "Name"); and in the View side I have used Ra...
Clarence asked 30/5, 2013 at 5:33

4

Solved

I have seen many posts about when to use ViewBag/ViewData vs ViewModel but i have not been able to find an explanation of the lifecycle of the ViewBag. For example, i have two Action methods in on...
Beginner asked 8/2, 2012 at 1:34

3

Solved

In ASP MVC C# I putted a List(Cars) in the ViewBag.cars, now I want to make an actionlink with the title of each car, like this: @if (ViewBag.cars != null) { foreach (var car in ViewBag.cars) { ...
Underplot asked 9/1, 2014 at 16:43

3

I'm trying to make a dropdownlistfor with a selected value but it doesn't work :/ And I search on the web but I don't find the solution :/ For the moment, I'm doing this : In C# : ViewBag.ID_VEH...
Gallic asked 23/7, 2013 at 8:37

1

Solved

i want to send two model in my view and in other page maybe and need more controller ViewBag.Users = db.Users.ToList(); and in View @using Documentation.Models @{ var Users = (Documentation....
Catalectic asked 7/11, 2013 at 18:20

© 2022 - 2024 — McMap. All rights reserved.