viewdata

Asp.net MVC User Control ViewData

When a controller renders a view based on a model you can get the properties from the ViewData collection using the indexer (ie. ViewData["Property"]). However, I have a shared user control that I tried to call using the following: return View("Message", new { DisplayMessage = "This is a test" }); and on my Message control I had this...

MVC Preview 5 - ViewData/HTML Helper Quirk

The following code is in the /Courses/Detail action: [AcceptVerbs("GET")] public ActionResult Detail(int id) { ViewData["Title"] = "A View Title"; return View(tmdc.GetCourseById(id)); } The tmdc.GetCourseById(id) method returns an instance of type "Course" for the View. In the View I am using <%= HTML....

MVC User Controls + ViewData

Hi im new to MVC and I've fished around with no luck on how to build MVC User Controls that have ViewData returned to them. I was hoping someone would post a step by step solution on how to approach this problem. If you could make your solution very detailed that would help out greatly. Sorry for being so discrete with my question, I wo...

Determining the results count of ViewData

Hi I have a view with several User Controls and I pass ViewData to all of them, I would like to know how you would determine the element count by specifying the string key. I understand that you cannot use comparison to an integer because ViewData is an object but I have it setup this way for explaining my question. I have also tried nul...

How do you use usercontrols in asp.net mvc that display an "island" of data?

I am trying to find out how to use usercontrols in asp.net mvc. I know how to add a usercontrol to a view and how to pass data to it. What I haven't been able to figure out is how do you do this without having to retrieve and pass the data in every single controller? For example, if I have a user control that displays the most recent ...

LINQ Anonymous Types + MVC Views Help

I've seen many questions about this, but i've never really got the answer that I need. I'm converting a fairly large web application from Web Forms to MVC and after a while I encountred a problem with passing data to the view. In the Action I execute the code: //This is just an example ViewData["QProducts"] = from p in db.Products s...

Passing information to usercontrol in ASP.NET MVC

hi everyone, I know how pass viewdata into a user control which is like this <% Html.RenderPartial("someUserControl.ascx", viewData); %> This is what i want to do: In the current situation i have events calendar and each section of my events calendar is a wired to a user control, so ideally when i pass a date value to my user contr...

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

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). T...

When upgrading to MVC beta to RC1 the application suddenly crashes where it shouldn't crash

When we upgraded MVC beta to MVC RC1 the development webserver that visual studio has suddenly crashed at some point in the application. After some searching I narrowed the bug to this simple line: if (!helper.ViewData.ContainsKey("SomeString")) SomeString is at that moment present in the viewData so the if statement should return fal...

Populating dropdownlist with selectlist in ViewData

I am trying to populate an HTML.Dropdownlist with a selectlist which is populated with a string value (a location address) and text (a location description) fields from a database call. I am passing the selectlist as viewdata to my view. The dropdown populates fine but when I go to use the value it is null or empty as seen by an alert I ...

Dropdownlist value not getting set from SelectList passed to view in ViewData

I am trying to populate a dropdownlist of office locations(text) and addresses (value) When viewing my page source in my browser after displaying the page I can see that the select (dropdownlist) option values are all "". Here is my code. I am using a LinqToSql data context call to get my data for the SelectList. In the debugger I can s...

Where should I put my asp.net-mvc strongly typed viewdata?

I've been nesting my viewdata classes inside my controllers and, as their numbers grow, I'm starting to ask myself if this is a good idea. Then again, something about polluting the /Views and /Controllers directories with these things seems off. Is there a convention I'm missing here? Maybe a /ViewData directory? idk, what are some good...

mvc no codebehind strongly typed viewdata headers not working

I add that to my header <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %> and am able to access ViewData and all its internals as well as all the mvc objects like url and html. As soon as I add "System.Web.Mvc.ViewPage<app.Models.tTable>" I have no access to any mvc classes and helpe...

strongly-typed partial views MVC RC1

having a problem passing ViewData.Model to the partial views. It always is defaulting to null even if I equate it to a result query. I cannot access the strongly typed data because the Model is null. My current code is this, ViewPage <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <% Html.RenderPartia...

MS MVC - Can I somehow globally fill in strongly typed ViewData/Model for all my Views?

I'd like to supply instance of logged User (or null if nobody logged yet) for all views in my MVC application. I've already succesfully implemented my own ControllerActionInvoker class which overrides InvokeAction and supplies logged user instance in ViewData (controllerContext.Controller.ViewData["LoggedUser"] = xxx). The problem is tha...

Need simple example of how to populate javascript array from Viewdata list

Hi - There may be a simpler way of doing this and I am all ears if there is. My situation is I have a dropdownlist on a form which I successfully populate with text and values. I also need to have additional related string values from the same table row in the db table available on the client so when the user selects from the dropdown t...

passing viewdata to asp.net mvc masterpages

I'm trying to pass ViewData to my asp.net mvc masterpage for an mvc usercontrol that I keep on a masterpage. For example, I created a dropdownlist of names as an mvc usercontrol and I put that in my masterpage. The problem I am running into is passing the ViewData to the masterpage. I found this article from Microsoft which has a decen...

Best way to CustomViewData?

What's the most practical way to add custom properties to a side wide ViewDataDictionary? Let's assume a simple case: public ActionResult Index() { // ViewData["Title"] = "Home"; ViewData.Title = "Home"; return View(); } The first thing that comes to mind is a custom class and using "new" in a application base controller: publ...

C# Centralizing repeating VIewData in MVC

When a user log in into my application i want to show his name throughout the whole application. I am using the asp.net MVC framework. But what i don't want is that is have to put in every controller something like: ViewData["User"] = Session["User"]; This because you may not repeat yourself. (I believe this is the DRY [Don't Repeat...

MVC strongly typed viewdata with arrays

I have a view that uses a strongly typed ViewData similar to this: namespace Site.web2.Models { public class MySubData { public string Note { get; set; } public bool IsValid { get; set; } } public class MyViewData { public int DataId { get; set;} public List<MySubData> SubData { get; s...