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
1 answer

Call Static Method of a class from Razor View on jQuery link Click and also passing Strongly typed viewbag

I am trying to pass Strongly Typed ViewBag from Controller to View, then from View call a static method on jquery link click which uses the View bag property as paramater. In Controller, I have public ActionResult LoginUser(string userName, string…
0
votes
1 answer

Changing the ViewBag inside a Controller that is NOT a child action, and retrieving it in the View context

Our application has a global Controller that all other Controllers inherit from; from within, in the OnResultExecuting override, I access an item (something obtained by accessing the Session, the HttpContext and the Web.config) that I store in…
Emanuele Ciriachi
  • 2,216
  • 2
  • 26
  • 39
0
votes
2 answers

Extension methods don't work on properties of a model instance passed via ViewBag

I have the following string extension method: public static string Truncate(this string value, int maxLength = 75) { /* ... */ } I want to use it in views, and it works properly with literal strings. But when I have a model instance (let's call…
nameless
  • 1,969
  • 11
  • 34
0
votes
1 answer

Viewbag not working in Explicit Partial View

I have a list view And i want to add a create partial to the page. @model IEnumerable @Html.Partial("_Quickblah", new blah.Domain.Entities.blah()); public ViewResult _Quickblah() { …
Evildommer5
  • 139
  • 3
  • 15
0
votes
3 answers

Using ViewBag in a switch statement

Here is the code in my controller: public ActionResult MyMethod(string widgetId) { ViewBag.Widget = widgetId; ViewData["widget"] = widgetId; return View(); } And here is what I tried in the switch statement: var sort…
petko_stankoski
  • 10,459
  • 41
  • 127
  • 231
0
votes
1 answer

Drop down list fails to bind/display selected model value when bound via Viewbag

I have the following code in the controller: ViewBag.CategoryName = new SelectList(catList, "key", "value"); where catList is a Dictionary where key is of type string and value is of type string. This dictionary is populated properly and contains…
Marko
  • 12,543
  • 10
  • 48
  • 58
0
votes
1 answer

convert string to double decimal point needs to be a point

I have been looking around here and I have found this solution: ViewBag.lon = double.Parse(parts[1], CultureInfo.InvariantCulture); this is doing the trick... partially... When I put this value in my ViewBag and write it out, the '.' becomes a ','…
user1122844
  • 87
  • 4
  • 13
0
votes
1 answer

ViewBag multiple SelectListItems

Getting some very annoying behaviour from my MVC3 app. So I've got a model with 3 values: [DisplayName("Airlines ")] [StringLength(2, ErrorMessage = "Airline codes can only be 2 characters in length")] public string AirlineCode1 { get; set;…
Liam
  • 27,717
  • 28
  • 128
  • 190
0
votes
1 answer

Check from JQuery if value exists in ViewBag

I trying to check if value in ViewBag exists or not from JQuery : if("<%: ViewBag.isSearchEnabled %>" != null && "<%: ViewBag.isSearchEnabled %>" != "True") { $("#CompanySearchPanel").hide(); } This should be working…
Nitish
  • 13,845
  • 28
  • 135
  • 263
0
votes
1 answer

I need to get data to my view

I have a view in my mvc intranet to create processes. In that view, I have a table that needs to be populated with data. This is my view @model TestingTool.ViewModels.ProcessModel @{ ViewBag.Title = "Create"; }

Create

Rui Martins
  • 2,164
  • 7
  • 33
  • 52
0
votes
1 answer

Passing a Value from a ViewBag to a partial View

So my Controller's code is as follows: private CommunityModelsContext dbCommunities = new CommunityModelsContext(); // GET: /Home/ public ActionResult Index() { //retrieve the Communities ViewBag.Communities =…
0
votes
1 answer

Pass variable back from EditorTemplate to page or layout

I am tired to google around and ddn't found the exact answer. I know I can pass date from view to template by additionalViewData parameter of .EditorFor() or .DisplayFor() but I want a data back from template! I have Date.cshtml in my…
CallMeLaNN
  • 8,328
  • 7
  • 59
  • 74
0
votes
0 answers

Transferring ViewBag variable between Controller and View

I am passing a ViewBag variable between my Controller and View and always has the same value of false. I verified during debugging that's it's not being overwritten. The purpose of it is that under a certain condition, I want to display some…
sagesky36
  • 4,542
  • 19
  • 82
  • 130
0
votes
2 answers

ViewBag null control in DropDownListFor

@Html.DropDownListFor(model => model.TransferAvailibilities.First().CancellationID, (ViewBag.CancellationSchema == null ? null : (IEnumerable)ViewBag.CancellationSchema), new { @class = "field large" }) And error: There is no…
Can Ürek
  • 641
  • 12
  • 24
0
votes
2 answers

Convert ViewBag to Model

public ViewResult Details(int ID) { tblMp3 item = db.tblMp3.Single(t => t.ID == ID); ViewBag.Mp3Tags= db.tblTags.Where(c => c.tblMp3.Any(a => a.ID == ID)).ToList(); return View(item); } This is my…
dr ammar
  • 57
  • 1
  • 1
  • 6