viewbag

How to parse objects from ViewBag to JavaScript?

你说的曾经没有我的故事 提交于 2019-12-11 18:54:51
问题 I am trying to parse an object from ViewBag to Javascript without luck. I have tried so far with jQuery/razor/mixed syntax...to no avail. When I tried with Json.Encode() , I get an "error not defined". Class class Story { public long Id {get;set;} public string Description{get;set;} } Controller [HttpGet] public IActionResult Index(Story _story) { List<Location> Locations = this.context.Locations.ToList(); ViewBag.story = _story; return View(context.Locations); } View $(document).ready

Make a Global ViewBag

余生颓废 提交于 2019-12-11 11:46:37
问题 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 that Dropdown I am passing the Value by making ViewBag.Company in each action. I want the solution:: 1) A Global ViewBag.Company having List that we are passing from each action. 2) Then there won't be any need to create ViewBag.Company in each Action. This question might be something different. But How

Visual Studio 2013 - Debugging MVC code with ViewBag properties deathly slow and unusable

浪尽此生 提交于 2019-12-11 07:26:09
问题 I'm trying out the latest Visual Studio, but debugging the most elementary MVC application with ViewBag dynamic variables gives me a lot of headache. I'm running Visual Studio 2013 under 32-bit Windows 8 operating system with clean install and every available update applied. I created new ASP.NET Web Application (.NET Framework 4.5 - New Solution) with folders and core references for MVC after which I added sample Home controller with some element code: dynamic d1 = 1; dynamic d2 = 2;

How to use ViewBag to pass list of data from View to controller

送分小仙女□ 提交于 2019-12-11 05:49:47
问题 how can i sen a list of items from a view to a controller to save it. i believe that i can use Viewbag but i dont realy no how to use ite to pass data from view to controller. this is what i have tried My view @using (Html.BeginForm()) { @Html.ValidationSummary(true) <fieldset> <legend>ProductionOrderItem</legend> <div class="editor-label"> @Html.Label("ProducrionOrderNo"); </div> <div class="editor-field"> @Html.TextBox("ProductionOrderNo", ViewBag.ProductionOrder as int) </div> <div class=

Return List To View

末鹿安然 提交于 2019-12-11 05:29:08
问题 Every Time I loop through the viewbag it gives this error object' does not contain a definition for 'Name' This My Action public ActionResult AssignTask() { var List = db.Employees.Select(x => new { id = x.id, Name = x.Name }).ToList(); ViewBag.Emp_data = List; return View(); } and this is my view 回答1: This code returns a List<anonymous> var List = db.Employees.Select(x => new { id = x.id, Name = x.Name }).ToList(); so that's why you can't access Name property in the foreach loop in your view

Passing data from controller to view

让人想犯罪 __ 提交于 2019-12-11 05:28:27
问题 I have a silly question : In my controller I set : ViewBag.totalCount = 20 In the view I want to call: @Html.Pager(8, 1, @ViewBag.totalCount); but I think that ViewBag is not recognized as the whole method call is underlined in VS. It has to be something simple. How can I so it please ? Thanks! 回答1: Just need @Html.Pager(8, 1, (int)ViewBag.totalCount) assuming it's an int (you need to cast as it will be dynamic ). No @ in front of ViewBag (since you're already in code) and, if pager returns

Maintaining ViewBag values while posting data

北战南征 提交于 2019-12-11 00:07:13
问题 I have a logical question that needs to be answered!! Here is a scenario.. -In controller ViewBag.Name = "aaaa"; -In View @ViewBag.Name "In my controller, i have set value for ViewBag and retrieved value from ViewBag in VIew. Now in View, i have a button, which is posting some data to a HttpPost method. In HttpPost method, i have changed the values for ViewBag. So after the execution of that method, the values in the viewbag will change or not for current view??" -In HttpPost Method ViewBag

Bind DropDownListFor with List on ViewModel

青春壹個敷衍的年華 提交于 2019-12-10 22:55:14
问题 I'm trying to do this: This is my ViewModel and Model: public class OpeningYearViewModel { public int OpeningYearId { get; set; } public string Description { get; set; } public List<Grade> GradesList { get; set; } } public class Grade { public int GradeId { get; set; } public string Name { get; set; } public int CurrencyId { get; set; } public int Cost { get; set; } } This is my Controller. I build a SelecList here and pass it to the view through the ViewBag OpeningYearViewModel viewmodel =

RenderPartial and ViewBag

谁都会走 提交于 2019-12-10 19:01:36
问题 I'm trying to modify this code: http://www.codeproject.com/Articles/260470/PDF-reporting-using-ASP-NET-MVC3 To make it to get the ViewBag data for render the View in the PDF. Basically, I need to pass to Html.RenderPartial with a new Context my ViewBag, the code now is: Html.RenderPartial(viewName, model); And I'm trying to change it to something like: Html.RenderPartial(viewName, model, new ViewDataDictionary(ViewBag)); I don't get any error but the Dictionary keeps empty. BR 回答1: Try

The name 'ViewData' does not exist in the current context

谁都会走 提交于 2019-12-10 18:59:36
问题 I am working over my first application over MVC3 and still kind of a newbie in it: I’m trying to success my ViewData[] over a master page because its contains a message that would be used over every page, but when I’m trying to access that it says: CS0103: The name 'ViewData' does not exist in the current context var msg = ViewData["msg"] as string; //var msg = ViewBag.msg as string; if (msg != null) { Response.Write (msg); } else if (msg == null) { Response.Write(""); } I am not sure whether