asp.net-mvc-2

How to create concurrent async requests when number of concurrent requests varies?

I have a controller that looks like the following: foreach(var setting in userSettings) { //connect to db here and run a 500ms query } The userSettings varies per user and so sometimes there are 2 settings which means 2 500ms queries need to run, while sometimes the user has 15 settings, meaning 15 500ms queries will run. Since ...

Adding custom convention rule to Automapper

I have been using Automapper to map from my entities to my ViewModels successfully. I was getting tired of having to mark my Add and Edit Models with the [Required] attribute so I decided to add a custom Metadata Provider that would take any property ending with "X" and make it required. Needless to say now the conventions in Automapper ...

How do I delete a record?

I'm trying to delete a database record using ASP.NET MVC, Fluent, and NHibernate. See the code below for examples of how I'm trying to accomplish this. I am able to Get, Update, and Insert records but Delete is not working. When the Delete() method gets called in the controller (top one) it throws an Exception (System.Data.SqlClient.SqlE...

Invalid casting exception on my simple application.

Here's the gist of it: There is a list of classes at my school. Each class belongs to a single Career. I'm creating the create a new class form, eg. Math, Social Studies, etc. On the form I want a dropdownlist to generate with the available Careers we offer. Unable to cast object of type 'System.Collections.Generic.List`1[System.We...

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

I'm having trouble when handling the Post request for my controller: [HttpGet] public ActionResult Crear() { CarreraRepository carreraRepository = new CarreraRepository(); var carreras = carreraRepository.FindAll().OrderBy(x => x.Nombre); var carrerasList = new SelectList(carreras, "ID", "Nombre"); ViewData["Carreras"] =...

Can I use an Html helper to render hyperlink with images?

Something like this <a id="a1" runat="server" href="~/"> <img id="logo" runat="server" src="/_assets/images/logo.png" alt="" /> </a> Thanks! ...

ASP.NET MVC 2 EditModel include Id? Securing Id is not tampered with

I am looking for some best practices when is comes to creating EditMoels and updating data in an ASP.NET MVC app. Lets say I have a Url like so /Post/Edit?Id=25 I am ensuring the user has permissions to edit the specific post by Id on the Get request and the same for my Post in the controller. I am using the ValidateAntiForgeryToken. Q...

Unity 2 property injection, how do I translate config to fluent syntax?

I have a httpHandler and using Unity 2 I would like to inject a dependency into my HttpHandler. My code looks like: public class MyHandler : BaseHandler { public MyHandler() { } public IConfigurationManager Configuration { get; set; } ... } Using the web.config I would configure it like...

ASP .NET VirtualPathProvider HttpCompileException

I have a VirtualPathProvider that is loading my aspx file content from a DB. All seems to be well and good except when my aspx file has a reference to a namespace or assembly that is not explicitly mentioned in my web.config. The solution seems easy right? Add assembly and import directives to the page... But that doesn't seem to work. ...

How to organize views, partial views and their view models?

I'm developing in asp.net mvc2. I am beginning to create a lot of views and partial views, for most of which I've had to create a view model. This is looking like soon it's going to become unmanageable to remember what view goes with what model. I've tried to use inheritance in my view models as much as possible. I'm wondering how other...

ASP.NET MVC2 User Profiles

Hi. What is the easiest way to create users with associated profiles in MVC2? Is there any library already having such functionality? Thanks in advance. ...

MvcContrib : returning an existing ViewResult does not redirect to the correct page.

I've the following scenario: Go to the /User.mvc?userId=200&otherId=1 page. Change some data. Press Update button. Show the /User.mvc?userId=200&otherId=1 page. I used MvcContrib + T4MVC with the following code: [AllRolesAuthorize()] public virtual ViewResult Index(long? userId, long? subPracticeId) { long selectedUserId = userI...

Sharing MasterPages and styles/other media between ASP.NET MVC sites, using MVCContrib PortableAreas

Any way to have a Portable Area containing resources common to several MVC applications (when added as a reference to the project depending on it)? Wanting to have a 'Core' set of pages, styles, masterpages, javascript etc, but not found an easy way to do this. Tried a few things to reference the master page, but not had any luck. The f...

ModelBinder NHibernate Complex Object with Collections

Below, on initial load (Edit), everything displays fine. However, when I POST (Action below), it looks like it goes and tries to grab the ProductAttribute models separately, with the Product's id, which promptly fails. How to keep my Binder implementation from trying to re-bind Collections as separate entities? Thanks! Model public ...

MVC 2 Html CheckBox Client-Side Validation

Hi, this is probably simple but has been driving me nuts. I have searched all over for this and found people that have mentioned it but no solution provided. I have a simple viewmodel that has a boolean property with no data annotations on, other properties do but these do not effect the problem. Public Property AcceptSurvey As Boolean...

Html.EditorFor in an MVCContrib PortableArea

I am trying to use Html.EditorFor in a Portable Area (i.e. so create and edit use the same form), but it doesn't seem to working (fine when it is not in the Portable Area though). In the page, I just have: <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MySite.Models.DocumentType>" %>...

SubSonic 3, Entity Data Model (Entity Framework) or LINQ to SQL for ASP.NET MVC development?

Having used all of them (some more than others), I am still undecided on which could be the best to use (with .NET 3.5). What are the pro's and con's of each when developing? SubSonic 3 Not enough samples/documentation (I know its a wiki and people can update it, but it can be tricky to track things down - e.g. where are the sample apps...

Mapping problem of ASP.NET MVC route with optional URL parameter

routes.MapRoute("Archive.CityState", "Archive/{City}/{State}/{OP1}/{OP2}", new { controller = "Archive", action = "CityState", OP1 = UrlParameter.Optional, OP2 = UrlParameter.Optional }, new { City="[a-zA-Z]+" ,State = @"[a-zA-Z]{2}", OP1 = @"[a-zA-Z]+" , OP2 =@"\d{4}" }); public ActionResult...

How to disable security for an Action in ASP.NET MVC?

My requirement is that only the login page and the Register page should be accessible from anonymous users. I have created a new ASP.NET MVC project using the default template in VS2008. After that I have enabled security adding this section to the web config: <authorization> <deny users="?" /> </authorization> Now t...

Help writing regular expression for validation in asp.net mc 2

I need my users to input very specific cell phone format cause my app will be sending sms to them So, I need their cell phone formats to be like this 04AB-XXXXXXX Where A can be either 1 or 2 and B can be either 2, 4 or 6 X can be from 0-9 There must be exactly 7 numbers (X) after 04AB It must always start with 04 Examples: ...