asp.net-mvc

Although not [required] List field shows up as required and Model State is not Valid due to it being null?

I have the following code- View- <% Html.BeginForm(); %> <div> <%= Html.DropDownList("DropDownSelectList", new SelectList( Model.DropDownSelectList, "Value", "Text"))%> Controller- public ActionResult Admin(string apiKey, string userId) { ChallengesAdminViewModel vm = new ChallengesAdminViewModel(); vm.ApiKey = apiKey;...

In ASP.NET MVC, how does response.redirect work?

I have used response.redirect in classic ASP and ASP.NET webforms. However, with MVC 2.0, I am running into something peculiar. I have a private method in a controller class that is used by multiple controller methods to help load and validate some information. This private method is setup to redirect if a problem is discovered to a...

How to use Custom AuthorizeAttribute for controller utilizing parameter value?

I am trying to secure a controller action to prevent a user from accessing an Entity that they do not have access to. I am able to do this with the following code. public ActionResult Entity(string entityCode) { if (CurrentUser.VerifyEntityPermission(entityCode)) { //populate viewModel... ...

Good sample of asynchronous comment system for ASP.NET MVC, JSON and JQuery

Good morning can anyone jot down a complete sample for creating an asynchronous comment mechanism like this, but focusing on ASP.NET MVC? ...

GetUtcOffset returning wrong timezone

Hi, for some reason when I use the following code TimeSpan timeDiffUtcServer = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now); it returns -07:00:00 offset I am using Windows XP and my timezone is set to Pacific time -08:00. I am running this through VS 2010's built in IIS server which is on my computer, so I can't figure out wh...

ASP.NET MVC - How to Unit Test boundaries in the Repository pattern?

Given a basic repository interface: public interface IPersonRepository { void AddPerson(Person person); List<Person> GetAllPeople(); } With a basic implementation: public class PersonRepository: IPersonRepository { public void AddPerson(Person person) { ObjectContext.AddObject(person); } public List<...

XML Validation in ASP.NET MVC during load

I'm writing an ASP.NET MVC 2 application where one of the backing stores I plan to support is XML. I have a POCO that represents the settings for the site, along with an XML file to contain these settings. My question is what is the best way to validate this data as it is read from disk in to the POCO? I know I can use an XSD, or mayb...

DotNetOpenAuth MVC samples - project type not supported

I have an issue with the DotNetOpenAuth sample projects. I have Visual Studio 2008, with MVC1 installed, yet when i try open the samples.sln the 2 MVC projects fail to load, giving the error: "Project type not supported" Is there additional requirements other than VS an MVC? ...

Conditionally add htmlAttributes to ASP.NET MVC Html.ActionLink

I'm wondering if it's possible to conditionally add a parameter in a call to a method. For example, I am rendering a bunch of links (six total) for navigation in my Site.Master: <%= Html.ActionLink("About", "About", "Pages") %> | <%= Html.ActionLink("Contact", "Contact", "Pages") %> <%-- etc, etc. --%> I'd like to include a CSS clas...

Use database field maxlength as html layout input maxlength best practice. asp.net mvc

Hello everybody, There are string length limitations in database structure (email is declared as nvarchar[30] for instance) There are lots of html forms that has input textbox fields that should be limited in length for that reason. What is the best practice to synchronize database fields and html layout input fields length limitations...

Using Castle Windsor with FluentValidation In MVC

I'm working on getting FluentValidation working with Castle Windsor. I already have a wrapper around Castle Windsor. Here is the code for that: public class ResolveType { private static IWindsorContainer _windsorContainer; public static void Initialize( IWindsorContainer windsorContainer ) { _windsorCont...

Active Directory Membership Provider - how to expand on this?

I'm working on getting an MVC app up and running via AD Membership Provider and I'm having some issues figuring this out. I have a base configuration setup and working when I login as [email protected] + password. <connectionStrings> <add name="MyConnString" connectionString="LDAP://domaincontroller/OU=Product Users,DC=my,DC=do...

MVC Authentication through WCF

In learning WCF, I'm a bit confused where to go to figure out how I should be handling user authentication. My MVC 2 app uses an Active Directory Membership Provider and this works and is good, but my MVC app doesn't really do anything but call my WCF services. My business logic on the other side of WCF is what really does everything (as...

can we get the multiple values from a select tag through Ajax script in controller in asp.net MVC?

can we get the multiple values from a select tag through Ajax script in controller in asp.net MVC? I Have tried for Single Value that I have done by .val Function.. But not for Multiple Values Any suggestion Please Help ...

Business rule validation of hierarchical list of objects ASP.NET MVC

I have a list of objects that are organized in a tree using a Depth property: public class Quota { [Range(0, int.MaxValue, ErrorMessage = "Please enter an amount above zero.")] public int Amount { get; set; } public int Depth { get; set; } [Required] [RegularExpression("^[a-zA-Z]+$")] public string Origin { get...

Using two versions of the same assembly (system.web.mvc) at the same time

I'm using a content management system whose admin interface uses MVC 1.0. I would like to build the public parts of the site using MVC 2. If I just reference System.Web.Mvc version 2 in my project the admin mode doesn't work as the reference to System.Web.Mvc.ViewPage created by the views in the admin interface is ambiguous: The type...

asp.net mvc formcollection

public ActionResult Edit(int id, FormCollection formValues) { // Retrieve existing dinner Dinner dinner = dinnerRepository.GetDinner(id); // Update dinner with form posted values dinner.Title = Request.Form["Title"]; dinner.Description = Request.Form["Description"]; dinner.EventDate = DateTime.Parse(Request.Fo...

Log client side errors to the server.

How can I log client side javascript errors to the server? I'm using jQuery and MVC. ...

Problem with View - it does not refresh after db update

Hi, I am working with small ASP.NET MVC project - online store. I have addToCart method which adds selected product to cart - it updates cart table in my db and showing cart view with its content. But I have problems. While db is updating correctly the view does not. I see that quantity of the product in my db is incremented correctly ...

When should one use asynchronous controller in asp.net mvc 2?

Thus far worked with asp.net mvc1 and just started with asp.net mvc2..... what are good candidates for executing a controller asynchronously? Should i use it for long running process or some background processing? What are the pros and cons choosing asynchronous controller in asp.net mvc 2? Any suggestion... ...