problem about viewbag-Collection of common programming errors


  • mattytommo
    c# asp.net-mvc performance viewbag
    When I think of a ViewBag, I associate it with the “final say.”Meaning you do all your logic and set the results to it.ViewBag.A = Some crazy math formula; ViewBag.B = Another crazy math formula; ViewBag.GrandTotal = Some crazy math formula + Another crazy math formula;This works as well:ViewBag.A = Some crazy math formula; ViewBag.B = Another crazy math formula; ViewBag.GrandTotal = ViewBag.A + ViewBag.B;Yipes, I am working with variables that formulate at runtime!Is this in anyway absurd or in

  • teresko
    asp.net-mvc razor viewbag
    For the ViewBag, I heard it was a no-no to use. I would assume have the content from the ViewBag should be incorporated into a view model?Question:Is my assumption above the best practice. (Not to use a ViewBag and second to have it in the view model) Are there situations where a ViewBag is absolutely necessary?

  • Shog9
    c# asp.net-mvc dynamic viewbag
    I am reading a book on ASP.NET MVC and I’m wondering how the following example works:Example #1Controllerpublic class MyController : Controller {public ActionResult Index(){ViewBag.MyProperty = 5;return View();} }View<h1>@ViewBag.MyProperty</h1>Now I understand that ViewBag is a dynamic object, so that’s how you can set the property (though I don’t know much about dynamic objects, never worked with them.) But how does the view get the specific instance of the ViewBag from the control

  • H.B.
    c# dynamic .net-4.0 asp.net-4.0 viewbag
    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 wondering how to go about creating an object with this behaviour?

  • Steve Newton
    linq asp.net-mvc-3 viewbag
    Does anyone have the faintest idea what this error means please and how to resolve it? All my research is drawing a blank, I can see how to set it on MSDN but it doesn’t explain it in a way that explains to me what the issue is. If I remove some of my LINQ queries to set viewbag items then it seems to resolve it but the moment I set new ones and pass them into my view to generate a mail for MVCMailer it comes back. Not sure if its a viewbag issue or simply that I am calling too many linq quer

  • Saeed Neamati
    asp.net-mvc-3 dynamic razor null viewbag
    Consider this simple controller:Porduct product = new Product(){// Creating a product object; }; try {productManager.SaveProduct(product);return RedirectToAction(“List”); } catch (Exception ex) {ViewBag.ErrorMessage = ex.Message;return View(“Create”, product); }Now, in my Create view, I want to check ViewBag object, to see if it has Error property or not. If it has the error property, I need to inject some JavaScript into the page, to show the error message to my user.I created an extension meth

  • Amanda
    javascript mvc viewbag
    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 side:<input type=”hidden” name=”diagramData” data-nodes=”@ViewBag.Tasks” />In my Javascript file, I would then search for the info related to the selected node:alert($(“#diagramData”).data(“nodes”)); //?????The alert always shows “undefined”. W

  • CaKaL
    asp.net asp.net-mvc-3 viewbag
    var Urun = (from u in db.urunlers.Where(x => x.Yayinlama == “1”)where u.UrunID == idselect new{u.UrunID,UrunAdi= u.UrunAdi,u.UrunAciklama,u.YorumIzni}).SingleOrDefault();ViewBag.urun = Urun;This is codebehind in my “.cs” page.var Urun = ViewBag.urun; <h3 class=”Baslik”><%:Urun.UrunAdi %></h3>This is my code “.aspx” page.But i get ‘object’ does not contain a definition for ‘UrunAdi’ error?I solved my problem via another method:JavaScriptSerializer js = new JavaScriptSerialize

Web site is in building