viewdata

There is no ViewData item with the key 'Blah' of type 'IEnumerable<SelectListItem>'.

This error message is driving me nuts. I'm getting it when using Html.ListBox and Html.DropDownList HtmlHelpers with ASP.NET MVC v1.0. Populating the lists works OK - I can view them, etc - but when I go to create a new record in the Model using the FormCollection passed into the Controller to get the selected value, this error occurs. ...

ASP.net mvc Common data for footer

So, I have a footer which will appear on every page of my web application I need it to render dynamic data so.... this means that every controller action needs to return viewData which contains this data.. as well as the action specific data How would you guys implement this? The constructor of a base controller perhaps? ...

In asp.net mvc, where do I put my strongly typed viewdata reference in my viewpage?

Hi, My viewpage doesn't have a codebehind, so how do I tell it to use a strongly typed viewdata? ...

Modelbinding lists

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: <%...

How do you persist querystring values in asp.net mvc?

What is a good way to persist querystring values in asp.net mvc? If I have a url: /questions?page=2&sort=newest&items=50&showcomments=1&search=abcd On paging links I want to keep those querystring values in all the links so they persist when the user clicks on the "next page" for example (in this case the page value would change, but t...

Strongly typed master pages polymorphism - nested masterpages ignore inherit attribute

I'm currently creating a CMS system and found that the following doesn't work. I do have a work around that isn't exactly ideal and feels dirty. I'm cool with it for now and not really that interested in a different approach (but don't let that stop you answering). What I am after is some kind of explaination on why it doesn't work - is...

ASP.NET MVC: How to handle cross-action TempData and ViewData

I'm trying to find a good way to handle the following scenario (I'm still kinda new to this): A user can register through my site using an RPX/OpenId provider. Step 1: The user authenticates through a provider. The provider returns a temporary token to one of my action methods. Step 2: I use the token to grab the user's profile inform...

ViewData not inheriting in partials

Hi, I was trying to use a shared partial view to render when a particular listing page has no data. I wanted to use ViewData to pass information from the page into my listing control, which would then conditionally render the NoData partial view using the ViewData values. I would like to be able to specify them in the view markup, ...

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

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 m...

Passing ViewData versus making a new class.

I've seen several posts on StackOverflow and elsewhere discussing the various ways to bring together data from multiple entities into a strongly typed view, these being using the ViewData object or constructing a new custom class that utilizes both entities. To me it seems that if you are representing some sort of new hybrid entity you ...

ASP.NET MVC - Pass Additional ViewData to a Strongly-Typed Partial View

I have a strongly-typed Partial View that takes a ProductImage and when it is rendered I would also like to provide it with some additional ViewData which I create dynamically in the containing page. How can I pass both my strongly typed object and my custom ViewData to the partial view with the RenderPartial call? var index = 0; foreac...

keep viewdata on RedirectToAction

[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 ...

ASP.NET MVC - How to pass an Array to the view?

Hello there, I'm struggling myself here, to find a easy way to pass an array from the controller to the view on ASP.NET MVC framework. so in my controller I would have something like: public class HomeController : ApplicationController { public ActionResult Index() { string[] myArray = { "value01", "value02", "value0...

Maintaining ViewData between RenderAction calls

I'm rendering a common Log-In form using Html.RenderAction, on every page of my site. If the user enters their details into the text-box and clicks 'Submit', it does a POST to a controller that handles the log in. If they make a mistake, such as entering an invalid email address, it will populate the ModelState with an error message an...

Can anyone tell me if and why I should void using ViewData in ASP.Net MVC?

Hi Guys This has probably come before and is probably very subjective. I have been tols to avoid using ViewData and use a FromViewModel class to pass informaiton to the view istead. Are there any major advantages of this approach? Thanks Davy ...

How to Preserve Value of JQuery Search in ASP.Net MVC

I have an MVC view where I have a search box. On keyup, I perform a JQuery search and render the results to a div> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <script language="javascript" type="text/javascript"> $(document).ready(function() { $("#SearchTextBox").keyup(function() { $("#MyEntity...

ViewData in ActionFilterAttribute - Object reference not set to an instance of an object.

Hello all, I've been trying to load masterpage content from database (based on a "TargetCode" in the querystring), using ActionFilterAttribute. However, I'm having problem setting the ViewData to the data returned from the database, here is the code: public override void OnActionExecuting(ActionExecutingContext filterContext) { Ho...

Is it acceptable to place view logic in a strongly typed view-data class?

Say you've got a view which requires some piece of data which requires some calculation, but no outside dependances. (For example, an enumerable string listing of the past 5 years.) Is it acceptable to place this in a strongly typed view class? Something like this: class HomeIndexViewData { // ...some view data... public IEnumerable<...

Return multiple views to one ActionResult with ASP.NET MVC

What I want to achieve essentially is: Items assigned to me Item 1 assigned to me Item 2 assigned to me Item 3 assigned to me All open items Item 1 open to everyone Item 2 open to everyone Item 3 open to everyone Item 4 open to everyone Though from what I have experienced of MVC so far is that I would have to return the data to the...

Keeping track of loaded scripts per page using ViewData

Hi all, I'm currently trying to find a good way to load my javascript files only when I need them. In order to do this, I created several HtmlHelpers for faceboxlinks, datepickerfields, tinymcefields and other scripts that need an external js and an initialisation jquery expression. In these helpers I execute the script using jQuery's g...