asp.net-mvc-2

Caching custom user properties in ASP.NET MVC

I have custom UserInfo and UserAuthorization objects in my app, which determine what is displayed and what actions a user can perform on each page. At the moment this information needs to be retreived for every request to the server. Would it be possible/sensible to cache this information somehow? Can anyone suggest some good google sear...

Localization in asp.net mvc

Friends, I'm working in asp.net mvc 2.0 and I'm stuck at the stage where I want to translate the site content (menu items, labels etc.) into predefined languages selected from the drop-down list. I want it to perform through asynchronous request (if possible). I have no prior experience in implementing globalization/localization in eith...

Making my first Create Page with ASP.Net MVC2

I am attempting to generate my first MVC application. I have a very basic table: Teams: ID,Name. I have created the MVC app ok and the table is listed. Below is the Create View. When it is run I get the message: A value is required. Can you help (sorry this is very basic). View create.aspx: <%@ Page Title="" Language="C#" MasterPa...

How do I unit test ASP.NET MVC2 model validation?

I'm using Nunit as my unit testing framework and I've created a couple of L2S entities and validation classes. Now I want to unit test the validation, but I can't figure out how to do that. This is my validation class: [Bind(Exclude = "ProjectID")] public class ProjectValidation { [Required(ErrorMessageResourceType = typeof(Valid...

Technical differences between ASP.NET and Java Servlets / JSP.

My understanding of JSP is that every JSP page on first load is compiled into a Java Servlet. Is this the same for ASPX pages (of course, not into a servlet, but whatever the ASP.NET equivilant is)? What other technical differences should I be aware of with JSP and ASP.NET (MVC 2)? ...

[Authorize(Roles="Admin")] attribute asks user to login instead of access denied?

Updated: Thanks to the help here I've created the following solution: public class CustomAuthorize : AuthorizeAttribute { protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext) { // Returns HTTP 401 - see comment in HttpUnauthorizedResult.cs // If user is not logged in prompt ...

How to Init start values in DropDown using Jquery

Hello! For example I have: <select id="myDropdown" name="myDropdown"> <option value="6">Six</option> <option value="5">Five</option> <option value="3">Three</option> <option value="1">One</option> </select> And I have controller: DBEntity context = new DBEntity(); // My EntityModel public ActionResult Index() { re...

Call an action in ASP.NET MVC 2 with MS Ajax without jQuery

How can I call an action in ASP.NET MVC 2 with MS Ajax when I don`t want to use jQuery? ...

ASP .Net MVC Custom Templating without DisplayFor

I currently have a display template for DateTime? objects that corrects the date depending on the user's time zone. This part of the program is working fine, and when I call DisplayForModel() or DisplayFor(m => m.Date), they both use the template and display the date and time with proper formatting. The problem I am having is I have a p...

Asp.net MVC Binding

If for example you have a Car class and that Car class contains a car type which is reflected by a table in the database. How do I get MVC to bind to car type when I create a new car? public class Car { public string Name { get; set; } public CarType Type { get; set; } } public class CarType { public int CarTypeId { get; ...

How can I apply CSS to an HTML text input?

Here is the ASP.Net MVC2 code that I use to display a textbox input. <div id="blackbar"> <p>Sistema de Evaluaciones de Docentes</p> <%: Html.TextBox("termino","") %> <img src="../../Content/search.png" alt="search" /> </div> Here is how it renders: <div id="blackbar"> <p>Sistema de Evaluaciones de Docentes</p> <in...

Global.asax does not map to Controller Action except for default in ASP.Net MVC2 on IIS5.1

I am a complete newbie, I have the default to be HomeController->Index When I hit, http: / /localhost /SampleApplication It goes to the index but I have another action "Process" in HomeController.If I hit http://localhost/SampleApplication/Home/Process returns resource not found. I am unable to get this in Visual Studio execute/Dev ...

jQuery Validation - adding required fields dynamically via ajax in MVC2

I'm trying to use jQuery validation on a form in MVC2. I'm using the: MicrosoftMvcJQueryValidation.js from the futures project. When the form first loads it is for the RepresentativeViewModel and there are three fields that are validated against. The validation works perfectly for them. A user may click on a link which loads in 3 addit...

How do I pass datetimes between a controller and a view in MVC?

Our model has public DateTime date { get; set; }. In our view, our dates are being stored in the JSON date format. We're then trying to save updates to the date var someObject = {}; someObject.date = JSONDate; $.post("Controller/SaveAction", someObject, callback); and our controller has public JsonResult SaveAction(ModelType mod...

Asp.net MVC2 IModelBinder is trying to drive me nuts (and succeeding)

Let's say I have class FooClass { } class BarClass { public FooClass Foo; } This BarClass is the Model I'm passing to the ViewPage. I'm also passing (via ViewData) an IEnumerable<SelectListItem> with all the Foo in it, and the one that match the bar.Foo is selected (checked at runtime). I'm then calling Html.DropDownList("Fo...

What does and does not belong in an ASP.Net MVC 2 Area folder?

Visual Studio tooling will create "Models", "Views" and "Controllers" folders in any new ASP.Net MVC 2 Area. What else should go into this folder? Would you (for example) place custom ModelBinders in Areas/MyReallyGreatArea/Binders if they are only referenced in MyReallyGreatArea? What is the best practice? ...

What is the correct way of Unit testing ViewEngines.Engines.FindView?

I recently did some refactoring of my mvc application and realized that there are alot of static views returned. Instead of having multiple controllers with action results that only return a view I decided to create one controller that returns the static views if they exists and throws a 404 error if the view doesn't exist. public Actio...

Plus (+) in MVC Argument causes 404 on IIS 7.0

I have an MVC route that is giving me hell on a staging server running IIS. I am running Visual Studio 2010's development server locally. Here is a sample URL that actually works on my dev box: Root/CPUBoards/Full+Size Results Server Error404 - File or directory not found. The resource you are looking for might have been removed, had...

Asp.net Mvc2 Ajax ImageActionLink Helper

I'm fairly new to Mvc and ran into a problem try to use an Image as an Ajax Action link. I found a helper that I believe was posted by Stephen Walther... using System.Web.Mvc; using System.Web.Mvc.Ajax; namespace Helpers { public static class ImageActionLinkHelper { public static string ImageActionLink(this AjaxHelper...

TempDataExtensions from the winter of 2007---still needed in MVC2?

This extremely cool article written in the winter of 2007 shows me this code: public static class TempDataExtensions { public static void PopulateFrom(this TempDataDictionary tempData, object o) { foreach (PropertyValue property in o.GetProperties()) { tempData[property.Name] = property.Value; } } public stati...