Search Results

Search found 386 results on 16 pages for 'viewdata'.

Page 1/16 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • ViewData.* and TModel in asp.net MVC

    - by Quintin Par
    After a week of asp.net mvc2, I still haven’t understood the advantages of ViewData.model or rather how I can properly utilize Viewdata. Can some teach me how to use Viewdata properly? Also what’s TModel that’s associated with viewdata? How does one utilize TModel? The viewdata explanation in spark view engine talks about TModel and I couldn’t get a clue of how I can use it in my projects. Can someone help me?

    Read the article

  • ASP MVC Access ViewData Array?

    - by Jacob Huggart
    I have some viewdata that is generated by going through my repository to the database to grab some scheduling info. When the information is stored in the Viewdata, I noticed that the viewdata is enumerated. How could I access the enumerated items and generate a table/list based on the viewdata? Most of the information just needs to be spit out into a table, but one item will have a link generated for it. Thanks!

    Read the article

  • asp.net mvc usercontrol viewdata

    - by kusanagi
    i have user control, which i render on several views. i want to show viewdata in the usercontrol, but viewdata must be filled in controller method, so i need to fill viewdata on each controller method of each view, where i render usercontrol. is there any simple solutions?

    Read the article

  • MVC JSON ViewData Question

    - by user325142
    Can ViewData be set & returned in an ActionResult that returns Json() ? Im asking because It's not working for me but when I put the same ViewData code into a Action method that returns a View() it works? Thanks

    Read the article

  • keep viewdata on RedirectToAction

    - by Thomas Stock
    [AcceptVerbs(HttpVerbs.Post)] public ActionResult CreateUser([Bind(Exclude = "Id")] User user) { ... db.SubmitChanges(); ViewData["info"] = "The account has been created."; return RedirectToAction("Index", "Admin"); } This doesnt keep the "info" text in the viewdata after the redirectToAction. How would I get around this issue in the most elegant way? My current idea is to put the stuff from the Index controlleraction in a [NonAction] and call that method from both the Index action and in the CreateUser action, but I have a feeling there must be a better way. Thanks.

    Read the article

  • ASP.NET MVC 2 - ViewData empty after POST

    - by Alex
    I don't really know where to look for an error... the situation: I have an ASPX view which contains a form and a few input's, and when I click the submit button everything is POST'ed to one of my ASP.NET MVC actions. When I set a breakpoint there, it is hit correctly. When I use FireBug to see what is sent to the action, I correctly see data1=abc&data2=something&data3=1234. However, nothing is arriving in my action method. ViewData is empty, there is no ViewData["data1"] or anything else that would show that data arrived. How can this be? Where can I start looking for the error?

    Read the article

  • Retain ViewData when editing variable length list

    - by Pieter
    I'm editing variable length lists and use ViewData to pass around information for filling a DropDownList. I use the method described here for editing these lists: http://blog.stevensanderson.com/2010/01/28/editing-a-variable-length-list-aspnet-mvc-2-style/ The data for this dropdownlist comes from the database. As the ViewData is not available across requests, I currently do a new query to the database each and every time. This also happens when the ModelState is not valid and the form is redisplayed. Of course, this is less then ideal even for a light-weight query as this one. How can I retain the information from that query across requests as long as the user is editing the page with that variable length list?

    Read the article

  • ASP MVC ViewData from one view to another (Html.Encode())

    - by Jacob Huggart
    Hello all, I have a page with a bunch of labels and checkboxes on it. On this page, the labels need to be easily customizable after the project is deployed. So I made all of the labels in this style: Html.Encode(ViewData["lblText"]) And I added a button on the page called "Edit Button Labels" that will only be seen by admins. When that button is clicked, I would like to load another view that simply contains a table of two columns. One column needs to contain the current labels and the other should have text boxes for the user to enter new labels. Then, once any changes have been made, I need to permanently change the "lblText" for each label on the original page. I have tried passing viewdata and tempdata to the "Edit Button Labels" view using both return view() and return RedirectToAction() with no success. Am I missing something minor or is there a better way to do this?

    Read the article

  • How to retrieve value from ViewData when the object is not a string?

    - by Richard77
    Hello, Here's the functionality I'd like to exploit: I've a class myClass and would like to iterate over a collection that contains all the properties of that class. I'd like to send the index of that collection along with the other data so that I can control the each sequence of the iteration. Here's simplified versions of a Action method and View (I'll use the same action-view for that functionality). 1) Action public ActionResult CreateHierarchy(int? index) { if(index < PropertiesOfMyClass.Lenght) { //Other code omitted ViewData["index"] = ((index == null) ? 1 : index++); Return View(); } } 2)View <% Using(Html.BeginForm()){%> //Other Code omitted <% = Html.Hidden("Index", ViewData["index"])%> <input type = "submit" value = "Do someting"/> <%}%> I've also placed this at the bottom of the page so that I can check the value of the index, <% = ViewData["index"]%> Unfortunately, its not working. I'm getting only the number 1. I'm missing something? such as a cast for the Viewdata? Should I write something like this: <% = Html.Hidden("index", (int)ViewData["index"])%> It's not working either Thanks for helping

    Read the article

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

    - by Jimbo
    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 have used exactly this setup in many places, but for some reason in this particular view I get the error: There is no ViewData item of type 'IEnumerable' that has the key 'submarket_0'.

    Read the article

  • ASP.NET MVC - Html.DropDownList - Value not set via ViewData.Model

    - by chrisb
    Have just started playing with ASP.NET MVC and have stumbled over the following situation. It feels a lot like a bug but if its not, an explanation would be appreciated :) The View contains pretty basic stuff <%=Html.DropDownList("MyList", ViewData["MyListItems"] as SelectList)%> <%=Html.TextBox("MyTextBox")%> When not using a model, the value and selected item are set as expected: //works fine public ActionResult MyAction(){ ViewData["MyListItems"] = new SelectList(items, "Value", "Text"); //items is an ienumerable of {Value="XXX", Text="YYY"} ViewData["MyList"] = "XXX"; //set the selected item to be the one with value 'XXX' ViewData["MyTextBox"] = "ABC"; //sets textbox value to 'ABC' return View(); } But when trying to load via a model, the textbox has the value set as expected, but the dropdown doesnt get a selected item set. //doesnt work public ActionResult MyAction(){ ViewData["MyListItems"] = new SelectList(items, "Value", "Text"); //items is an ienumerable of {Value="XXX", Text="YYY"} var model = new { MyList = "XXX", //set the selected item to be the one with value 'XXX' MyTextBox = "ABC" //sets textbox value to 'ABC' } return View(model); } Any ideas? My current thoughts on it are that perhaps when using a model, we're restricted to setting the selected item on the SelectList constructor instead of using the viewdata (which works fine) and passing the selectlist in with the model - which would have the benefit of cleaning the code up a little - I'm just wondering why this method doesnt work.... Many thanks for any suggestions

    Read the article

  • Accessing Linq Values in ViewData

    - by Jemes
    I'm having trouble accessing the id, area and theme values in my ViewData. They are being set in my action filter but when I get to the Site.Master I don't have access to them. Any help or advice would be great. ActionFilter public override void OnActionExecuting(ActionExecutingContext filterContext) { int SectionID = Convert.ToInt32(filterContext.RouteData.Values["Section_ID"]); int CourseID = Convert.ToInt32(filterContext.RouteData.Values["Course_ID"]); if (CourseID == 0) { filterContext.Controller.ViewData["Styles"] = (from m in _dataContext.Styles where m.Area_ID == SectionID select new {theme = m.Area_FolderName }).ToList(); } else { filterContext.Controller.ViewData["Styles"] = (from m in _dataContext.Styles where m.Course_ID == CourseID select new { theme = m.Course_FolderName }).ToList(); } } } Site.Master <%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" % <%@ Import Namespace="Website.Models" % <% foreach (var c in (IEnumerable<Styles>)ViewData["Styles"]) { Response.Write(c.Theme); }%>

    Read the article

  • How does MVC ViewData work?

    - by Matt
    I am toying around with an MVC application just to learn the technology. I am mocking up a check register application that keeps track of a checking account, what has cleared the bank and what has not. I am using EF for my model and everything seems to be working correctly insofar as Edit, Create, etc. However, I have a couple of totals at the top. One to show the bank's balance and another to show the actual balance. It works most of the time but when I do Edit's it does not always accurately reflect the new total and I need it to update everytime a change is made (i.e when something clears the bank): [Authorize(Roles = "admin, checkUser")] public ActionResult Index() { var resultSet = from myChecking in chk.tblCheckings orderby myChecking.id descending select myChecking; ViewData.Model = resultSet.Take(45).ToList(); //for balances var actualBalance = from theChecking in chk.tblCheckings select theChecking.deposit - theChecking.withdrawal; var bankBalance = from theChecking in chk.tblCheckings where theChecking.cleared == true select theChecking.deposit - theChecking.withdrawal; //get bank balance ViewData["bankBalance"] = bankBalance.Sum(); //get actual balance ViewData["actualBalance"] = actualBalance.Sum(); return View(); } I am showing the actual and other balance in the Index view as follows: <td colspan="9" style="text-align: center; font-size: 11pt; color: white;"> <%= string.Format("Bank Balance: {0:c}", ViewData["bankBalance"]) %> ------ <%= string.Format("Actual Balance: {0:c}", ViewData["actualBalance"]) %> </td>

    Read the article

  • Caching asp.net viewdata

    - by Tomh
    Hey guys, I'm currently thinking about caching most of my viewdata excpt user specific data after a user logs on. I thought the simplest way was caching the ViewData object itself and adding the user specific data after it was loaded. Are there any downsides of this approach? Are there better ways? string cacheKey = "Nieuws/show/" + id; if (HttpRuntime.Cache[cacheKey] != null) { ViewData = HttpRuntime.Cache[cacheKey] as ViewDataDictionary; } else { // add stuff to view data HttpRuntime.Cache.Insert(cacheKey, ViewData, null, DateTime.Now.AddSeconds(180), Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null); }

    Read the article

  • asp.net viewdata

    - by mazhar
    public ActionResult AddDinner() { Dinner dinner = dinnerRepository.GetDinner(id); ViewData["dinner"] = repository.AllDinners(); return View(dinner); } 1) First of all both the dinner object and the ViewData["dinner"] is passing to the view? 2) Secondly how would I iterate over the ViewData["dinner"] in the view?

    Read the article

  • How to handle ViewData type casting in MVC

    - by Wondering
    Hi All, I am new to MVC and facing one issue. I have a xml file and i am retrieving its value using Linq to xml and assigning it to ViewData. Controller.cs var res=from x in doc.Descendants("person") select new { Fname=x.Element("fname").Value, Lname=x.Element("lname").Value }; ViewData["Persons"]=res; in View I am trying <% foreach (var item in ViewData["Persons"]) { %> <li> <%= item.Fname %> </li> <% } %> but foreach (var item in ViewData["Persons"] is giving type casting error..what should be the exact type csting so that i can retrive values in the format item.Fname. Thanks.

    Read the article

  • View Models (ViewData), UserControls/Partials and Global variables - best practice?

    - by elado
    Hi I'm trying to figure out a good way to have 'global' members (such as CurrentUser, Theme etc.) in all of my partials as well as in my views. I don't want to have a logic class that can return this data (like BL.CurrentUser) I do think it needs to be a part of the Model in my views So I tried inheriting from BaseViewData with these members. In my controllers, in this way or another (a filter or base method in my BaseController), I create an instance of the inheriting class and pass it as a view data. Everything's perfect till this point, cause then I have my view data available on the main View with the base members. But what about partials? If I have a simple partial that needs to display a blog post then it looks like this: <%@ Control Language="C#" AutoEventWireup="true" Inherits="ViewUserControl<Post>" %> and simple code to render this partial in my view (that its model.Posts is IEnumerable<Post>): <%foreach (Post p in this.Model.Posts) {%> <%Html.RenderPartial("Post",p); %> <%}%> Since the partial's Model isn't BaseViewData, I don't have access to those properties. Hence, I tried to make a class named PostViewData which inherits from BaseViewData, but then my containing views will have a code to actually create the PostViewData in them in order to pass it to the partial: <%Html.RenderPartial("Post",new PostViewData { Post=p,CurrentUser=Model.CurrentUser,... }); %> Or I could use a copy constructor <%Html.RenderPartial("Post",new PostViewData(Model) { Post=p }); %> I just wonder if there's any other way to implement this before I move on. Any suggestions? Thanks!

    Read the article

  • Why Html.DropDownListFor requires extra cast?

    - by dcompiled
    In my controller I create a list of SelectListItems and store this in the ViewData. When I read the ViewData in my View it gives me an error about incorrect types. If I manually cast the types it works but seems like this should happen automatically. Can someone explain? Controller: enum TitleEnum { Mr, Ms, Mrs, Dr }; var titles = new List<SelectListItem>(); foreach(var t in Enum.GetValues(typeof(TitleEnum))) titles.Add(new SelectListItem() { Value = t.ToString(), Text = t.ToString() }); ViewData["TitleList"] = titles; View: // Doesn't work Html.DropDownListFor(x => x.Title, ViewData["TitleList"]) // This Works Html.DropDownListFor(x => x.Title, (List<SelectListItem>) ViewData["TitleList"])

    Read the article

  • ASP.NET MVC Html.Display() using ViewData?

    - by JK
    When I use Html.DisplayFor() using a property of the model, it comes out nicely with both a label for the property name and a textbox or label with the property value: Html.DisplayFor(model => model.FirstName) // renders as First Name: Joe Smith But if I try to use the same for something that is in ViewData, it doesn't seem to have any way to specify the text that will be used in the label in the rendered html: Html.Display(ViewData["something"].ToString()) // renders as (no label) something The other Html.Display() parameters don't look helpful: Html.Display(ViewData["something"].ToString(), "TemplateName", "HtmlElementId", {additionalData}) It looks like the only place I might pass the label is with the additionalData param, but I haven't found any examples or docs on how to do this.

    Read the article

  • ASP.NET MVC Filters: How to set Viewdata for Dropdown based on action paramter

    - by CRice
    Hi, Im loading an entity 'Member' from its id in route data. [ListItemsForMembershipType(true)] public ActionResult Edit(Member someMember) {...} The attribute on the action loads the membership type list items for a dropdown box and sticks it in viewdata. This is fine for add forms, and search forms (it gets all active items) but I need the attribute to execute BASED ON THE VALUE someMember.MembershipTypeId, because its current value must always be present when loading the item (i.e. all active items, plus the one from the loaded record). So the question is, what is the standard pattern for this? How can my attribute accept the value or should I be loading the viewdata for the drop down in a controller supertype or during model binding or something else? It is in an attribute now because the code to set the viewdata would otherwise be duplicated in each usage in each action.

    Read the article

  • ASP.NET MVC Filters: How to set Viewdata for Dropdown based on action parameter

    - by CRice
    Hi, Im loading an entity 'Member' from its id in route data. [ListItemsForMembershipType(true)] public ActionResult Edit(Member someMember) {...} The attribute on the action loads the membership type list items for a dropdown box and sticks it in viewdata. This is fine for add forms, and search forms (it gets all active items) but I need the attribute to execute BASED ON THE VALUE someMember.MembershipTypeId, because its current value must always be present when loading the item (i.e. all active items, plus the one from the loaded record). So the question is, what is the standard pattern for this? How can my attribute accept the value or should I be loading the viewdata for the drop down in a controller supertype or during model binding or something else? It is in an attribute now because the code to set the viewdata would otherwise be duplicated in each usage in each action.

    Read the article

  • asp.net mvc viewdata

    - by mazhar kaunain baig
    <% foreach (var Lang in ((IEnumerable<Egovt.Models.Language>)ViewData["Languages"])) { %> <div id="tabs-<%=Html.Encode(Lang.int_LangId) %>"> <% foreach (var OrganizationMeta in ((IEnumerable<Egovt.Models.OrganizationMeta>)ViewData["OrganizationMeta"])) { %> <% if (OrganizationMeta.vcr_DateType == "text") { %> <%=Server.HtmlDecode(OrganizationMeta.vcr_MetaValue)%><br /> <a href="#"></a> <% } else if (OrganizationMeta.vcr_DateType == "file") { %> <img alt="Image" src="../../Content/Logo/dd.gif" /> <% } %> <% } %> </div> <% } %> I want to base my second loop on the basis of first loop on the langid field, there are many ways but what you guys will use

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >