viewbag

Filter Excel Output using MVC 3

♀尐吖头ヾ 提交于 2019-12-24 21:22:15
问题 I am trying to filter the rows that are sent to a excel file. I have been able to figure out how to export row data to excel, but now I need to send filtered data to an excel sheet since I added a version dropdown. What happens is I select the version I want to see from the dropdown. Ex. the version is 12.1. The view will only bring back data that has a version number 12.1 associated with it. Now when I want to download the filtered rows in an excel file. I press the download to excel file

Foreach ViewBag data gives 'object' does not contain a definition for 'var'

╄→尐↘猪︶ㄣ 提交于 2019-12-23 19:42:49
问题 I have a controller that is building a query from Linq to Sql to pass into the ViewBag.products object. The problem is, I cannot loop using a foreach on it as I expected I could. Here's the code in the controller building the query, with the .ToList() function applied. var products = from bundles in db.Bundle join bProducts in db.BundleProducts on bundles.bundleId equals bProducts.bundleID join product in db.Products on bProducts.productID equals product.productID join images in db.Images on

How can my ViewData be null, but expandable in the debugger?

谁说胖子不能爱 提交于 2019-12-23 08:52:58
问题 Just came across an interesting effect while debugging a View. The scenario is easy to reproduce - I have a breakpoint in a View , in the Watch window I add ViewBag.ViewData and the value is null . However, if I just add ViewBag and expand the object, I can see the ViewData and it is not null . I can also successfully expand it and see its properties. Can anyone explain whether it's a bug or what causes this behavior? EDIT ViewBag.ViewData is actually null . E.g. if I have this code in the

Pass Objects from a controller to a view MVC [duplicate]

丶灬走出姿态 提交于 2019-12-23 03:50:34
问题 This question already has answers here : ViewModels or ViewBag? (2 answers) Closed 3 years ago . I started in a new job, we must create an app using MVC 5, i have no experience in .NET so I not sure if I am using the best practice. I have 2 models ClassRom and Students, public class Student { public int ID { get; set; } public string Name { get; set; } public int Age { get; set; } } public class ClassRom { public int ID { get; set; } public string Name { get; set; } } I am passing a

Returning a list to strongly typed view using viewbag

China☆狼群 提交于 2019-12-23 02:59:07
问题 I am trying to return a list of customers to a strongly typed view using the viewbag and am having some difficulties as im new to MVC and Razor, can anyone kindly offer any advice on the following problem please? I have the following Code in my controller, public ViewResult Index() { var q = from a in db.Customers select a; ViewBag.customer = q; return View(db.CustomerSites.ToList()); } and this code in my view @foreach (var customer in Model) { <tr> <td> @ViewBag.customer.CustomerName <td>

How to create view to display list of files in ASP.Net MVC 4 project

瘦欲@ 提交于 2019-12-23 02:36:10
问题 I am learning ASP.Net MVC 4 Programming. Currently, I want to display the list of files to the web page. Following is what I did till now. In the HomeController.cs I edited the Contact action as follows: public ActionResult Contact() { ViewBag.Message = "Your file page."; DirectoryInfo dirInfo = new DirectoryInfo(@"c:\"); List<string> filenames=dirInfo.GetFiles().Select(i=>i.Name).ToList(); ViewBag.data = filenames; ///^^ Is this correct?? return View(); } I want the filenames to be displayed

Store a value in ViewBag from javascript

◇◆丶佛笑我妖孽 提交于 2019-12-21 07:24:14
问题 How can I store a value in the ViewBag accessing it from javascript? 回答1: You cannot store a value in ViewBag from javascript. ViewBag is a server side concept and exists only on the server. Javascript runs on the client. As far as storing some data from ViewBag into a javascript variable is concerned you could use the following: <script type="text/javascript"> var foo = @Html.Raw(Json.Encode(ViewBag.FooBar)) </script> Now this being said I always advice people against using ViewBag/ViewData

How does ViewBag in ASP.NET MVC work behind the scenes?

∥☆過路亽.° 提交于 2019-12-21 03:09:13
问题 I am reading a book on ASP.NET MVC and I'm wondering how the following example works: Example #1 Controller public 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

Passing strings with Single Qoute from MVC Razor to JavaScript

久未见 提交于 2019-12-20 18:31:54
问题 This seems so simple it's embarrassing. However, the first question is when passing a value from the new ViewBag in MVC 3.0 (Razor) into a JavaScript block, is this the correct way to do it? And more importantly, where and how do you apply the proper string replacement code to prevent a single quote from becoming &#39 as in the resultant alert below? Adding this into a single script block: alert('@ViewBag.str') // "Hi, how's it going?" Results in the following alert: 回答1: Razor will HTML

Passing strings with Single Qoute from MVC Razor to JavaScript

别等时光非礼了梦想. 提交于 2019-12-20 18:31:06
问题 This seems so simple it's embarrassing. However, the first question is when passing a value from the new ViewBag in MVC 3.0 (Razor) into a JavaScript block, is this the correct way to do it? And more importantly, where and how do you apply the proper string replacement code to prevent a single quote from becoming &#39 as in the resultant alert below? Adding this into a single script block: alert('@ViewBag.str') // "Hi, how's it going?" Results in the following alert: 回答1: Razor will HTML