viewdata

ASP MVC Access ViewData Array?

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

Why Html.DropDownListFor requires extra cast?

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 = n...

Additional information in ASP.Net MVC View

I am attempting to implement a custom locale service in an MVC 2 webpage. I have an interface IResourceDictionary that provides a couple of methods for accessing resources by culture. This is because I want to avoid the static classes of .Net resources. The problem is accessing the chosen IResourceDictionary from the views. I have conte...

Changing parent view data variable from an action returning a partial view as AJAX request

Hello, I ran into a situation that I have never ran into before, hoping someone can help. I have a client that wants to be able to run a totally new ad-hoc report, or pick one from a drop down list. When chosen, it does a foreach through filter criteria objects nested in the report object. I had some initial trouble, because there was...

ASP.NET MVC ViewData and view model best practices

The initial situation is that I map my domain model into a presentation model. I have to display an update/create formular with textboxes and a dropdownlist. Should the viewmodel contain a list for the dropdownlist or should I pass the data for the dropdownlist by using ViewData? When schould I use ViewData and when don't I should use...

Code generation for views broken when using custom MVC ViewData classes.

I'm by no means lazy, but already 2 days overdue on our current sprint in my first ever MVC project, so I've been using the Add View Wizard to generate strongly typed views, but now that I have started using ViewData classes as view models, the wizard generates fields for ViewDataBase, and not my derived ViewData. I think that the deriv...

Alternative way to use ViewData in the View of an ASP.Net MVC Application

Hi, I am have been working on an ASP.NET Application. When passing data from the Controller to the View I have been doing the following- <%foreach(myModel classified in(IQueryable<MyModel>)ViewData["Classifieds"]) {%> <p><span class="Bold">Title:</span> <%: classified.Header %></p> <p><span class="Bold">Price: £ </span><%...

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

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

Help with asp.net mvc and ViewData in MasterPage

In order to avoid having to pass Data that goes in the master page of my site before every view in every controller I have created an ApplicationController that sets the data on its constructor... the problem with this approach is that one of the viewdatas I must pass is the url of the profile Image of the current logged in user. [Autho...

When is it right to use ViewData instead of ViewModels?

Assuming you wanted to develop your Controllers so that you use a ViewModel to contain data for the Views you render, should all data be contained within the ViewModel? What conditions would it be ok to bypass the ViewModel? The reason I ask is I'm in a position where some of the code is using ViewData and some is using the ViewModel. I...

ViewData["s"].ToString() vs. Request.QueryString["s"].ToString(), what is returned if "s" was never set?

If in my controller: public ActionResult Index() { //no code implied return View; } Then in the view that is returned: <%if(ViewData["SomeString"].ToString() != "True") {%> show this <%}%> I will get an error at runtime because of an object reference having no object. However inside of a page where I do: <%if(Request.Qu...

HTML markup rendering issue in ViewData? Also, MultiView functionality in MVC?

Hi, i'm trying to populate a ViewData instance with html markup like shown below. When the page renders, the html tags get rendered as text and not html markup. Anyone know why? Controller code: if (user.ActivationStatus == false) { ... ViewData["Message"] = "<p>Your account has been activated, you're good to go.</p>"; } el...

Can you put a PartialView into a ViewData object?

Hi, I'm trying to mimic the webforms multiview functionality and the only way i can think of is to put a PartialView into a ViewData object? Something like the following: View code: <%= ViewData["PartialViewPlaceholder"] %> Controller code: if(//condition){ ViewData["PartialViewPlaceholder"] = partialView1; } else { View...

Passing and returing data to a simple grid form using ASP.NET MVC

Hi I have page with a simple table and advanced search form. I pass List<Customers> to the model: View(List<Customers>); So what is best way to pass and return data to the search form? I want to use validation or something but I think passing data through ViewData is not good idea. Any suggestions? ...

How can I display a message in a master page with ViewData?

How can I display a message on the master page. The message is sent by the action. public ActionResult DisplayMessage() { ViewData["hello"] = "Hello!"; return View(); } ...

ASP.NET MVC: Passing instance variables to the View like in Ruby

Yes, I know that in ASP.NET MVC you have to use ViewModels. But I'm tired of writing countless amounts of ViewModel classes. Besides I'd like to just pass the Validation model to the view, instead of that I have to pass the whole ViewModel, so I get ugly code like Html.TextBoxFor(m => m.TopicModel.Title) Instead of Html.TextBoxFor(m...

ASP.NET MVC: Passing several objects to the view including a validation model

I like using Models for validation <!-- ViewPage --> <%@ Page Language="C#" Inherits="ViewPage<TopicModel>" %> ... <%= Html.TextBoxFor(m => m.Title) %> ... <%= Html.TextBoxFor(m => m.Description) %> // Controller [HttpPost] public ActionResult NewTopic(TopicModel model) { // validate } It works great, but when I need to p...

ASP.NET MVC: Sending data to views in POST requests

I have the following code: public ActionResult Foo() { var a = "a"; return View(new FooModel { A = a}); } [HttpPost] public ActionResult Foo(....) { // I need to set all the values of the ViewModel again, not to get a null exception in the view return View(new FooModel { A =...

The new ViewModel doesn't obsolete the ViewModel pattern in ASP.NET MVC 3, right?

In my understanding, the ViewModel pattern was designed to pass all the relevant data to View because 1) the view shouldn't perform any data retrieval or application logic and 2) it enables type-safety, compile-time checking, and editor intellisense within view templates. Since dynamic expressions are defined at runtime, does this mean ...

asp.net mvc c# - property EntryList of ViewData class..

I dont know where is my problem to access EntryList in ViewData. <%= Html.RenderPartial("LogOnControl", new NISE.Web.TestForum.Views.Shared.PaginationViewData() { PageIndex = ViewData.*EntryList*.PageIndex, TotalPages = ViewData.*EntryList*.TotalPages, PageActionLink = Url.Action("List","Entry", new { category = Vi...