viewdata

Can you help with this MVC ViewModel issue?

断了今生、忘了曾经 提交于 2019-12-25 02:47:37
问题 I have a problem with an MVC view that I just cannot seem to solve. Here it is. 1) I have an index view that displays a list of retailers with data from the retailers table. So far so good. 2) I also want to include the retailer categories for each retailer which are stored in a RetailersCategories table where each retailer can have multiple categories I have tried a few things but cannot seem to make this work. The closest I came to what I wanted was using a view model. I have included the

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

Thunderdome MVC- Why one-model-in in MVC?

删除回忆录丶 提交于 2019-12-23 08:53:22
问题 When Jeremy & Chad posted about their FubuMvc project, one of the differentiators they mentioned was their "Thunderdome Principal": The “Thunderdome Principle” – All Controller methods take in one ViewModel object (or zero objects in some cases) and return a single ViewModel object (one object enters, one object leaves). The Controller classes will NEVER be directly exposed to anything related to HttpContext. Nothing makes me cry like seeing people trying to write tests that mock or stub that

ViewBag vs ViewData performance difference in MVC?

痞子三分冷 提交于 2019-12-20 09:48:01
问题 I know that ViewData and ViewBag both use the same backing data and that neither are as good as using strongly typed models in most cases. However when choosing between the two is the dynamic nature of ViewBag slower than using ViewData? 回答1: Okay - my initial answer basically said 'no' - time for a bit of a u-turn. It should be 'no' in a perfect dynamic world - but upon closer inspection it would appear that there will either be no difference (accounting for JIT magic) or it might be ever-so

ASP.NET MVC - Pass Json String to View using ViewData

北战南征 提交于 2019-12-18 12:23:14
问题 I'm trying to pass Json to my View using ViewData Controller ViewData("JsonRegionList") = Json(RegionService.GetActiveRegions()) view $("input#UserRegion").autocomplete({ source:"<%: ViewData("JsonRegionList").ToString %>", minLength: 3, but the problem I'm running into is the output source looks like $("input#UserRegion").autocomplete({ source:"System.Web.Mvc.JsonResult", minLength: 3, which is obviously not right. Am I missing something basic? 回答1: The Json() controller method returns a

There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'xxx'

邮差的信 提交于 2019-12-17 04:02:53
问题 There are a couple of posts about this on Stack Overflow but none with an answer that seem to fix the problem in my current situation. I have a page with a table in it, each row has a number of text fields and a dropdown. All the dropdowns need to use the same SelectList data so I have set it up as follows: Controller ViewData["Submarkets"] = new SelectList(submarketRep.AllOrdered(), "id", "name"); View <%= Html.DropDownList("submarket_0", (SelectList)ViewData["Submarkets"], "(none)") %> I

Modelbinding lists

只谈情不闲聊 提交于 2019-12-14 04:22:14
问题 I got a controller action like public class Question { public int Id { get;set; } public string Question { get;set; } public string Answer { get;set; } } public ActionResult Questions() { return View(GetQuestions()); } public ActionResult SaveAnswers(List<Question> answers) { ... } the view> looks like: <% for (int i = 0; i < Model.Count; i++) { %> <div> <%= Html.Hidden(i.ToString() + ".Id") %> <%= Model[i].Question %> <%= Html.TextBox(i.ToString() + ".Answer") %> </div> <% } %> Obviously

MVC 3 Razor - Access ViewData in Ajax Request (Jquery, JavaScript)

懵懂的女人 提交于 2019-12-12 18:33:10
问题 I am writing some code where the user can check if a username already exists in the database before submitting the form. This works by on onkeyup event handler which takes the value from the textbox and passing it to an ajax request which calls my ActionResult method with a string parameter. My SQL logic works okay, I recieve a value which says already exists or not. The problem I have is from my Controller, I want to return the value. In the success part of my Jquery Ajax request I am trying

Combine 2 Entity Framework Model fields in 1 SelectList?

﹥>﹥吖頭↗ 提交于 2019-12-12 04:56:46
问题 I am attempting to display 2 fields from my INV_Locations Model within a SelectList: location_dept|location_room or for example IT|Storage . Using THIS post I pieced the below together via ViewData : INV_AssetsController - Edit() GET : public async Task<ActionResult> Edit(int id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } INV_Assets iNV_Assets = await db.INV_Assets.FindAsync(id); if (iNV_Assets == null) { return HttpNotFound(); } ViewBag.History =

Refresh viewData object in renderPartial

夙愿已清 提交于 2019-12-12 04:07:57
问题 I need help with this.. I have a viewdata with a list of clients and i feed it when the Index action method is called. /* Index action is the method that open the view. */ Once that the Index method was called, the variable is feeded and view is showed. Then, i have a dialog where is render a partialView, wich have a table with the list of clients. <div id="popupClients" class="popUp" style= "display:none"> <% Html.RenderPartial("ClientsPartialView", ViewData["clients"]); %> /* popupClients