asp.net-mvc

Struggling with SelectList in ASP.NET MVC 2

I have a model that looks something like this: public class SampleModel { public static SampleModel Create() { return new SampleModel { Boolean = true, // set several more properties... Colors = new SelectList(new[] { "Red", "Green", "Blue" }, "Green") }; } pub...

How can I add custom URL parameters to a MVC RedirectToAction

Hi I currently have a simple MVC RedirectToAction action... return RedirectToAction("Edit", "Customers", new {Id = iNewId}); ... which redirects to Cutomers/Edit/1 However I’d like to append some custom values to the URL which will get used by javascript, returning URLs such as Cutomers/Edit/1#Tab1 What is the best method of doing ...

should formcollection be empty on asp.net mvc GET request

i am posting a simple action. public void Login(FormCollection formCollection) { ... } Even with few querystring values, the formcollection.Count is 0. Is it by behaviour? ...

Base Class Access a Parameter

Is it possible for a Controller Base class to access a parameter from an action link and if so how do I access that parameter within my Base Controller? Action Link: <%=Url.Action("Area_1419", "Home", new { SectionId = 1})%> Base Controller Class: using System; using System.Collections.Generic; using System.Linq; using System.Web; u...

How do I determine the source of unpredictable LINQ query results?

I've been working on an application that uses xVal's server side validation with data annotations. We recently ran into errors where the validation messages have been unpredictable for fields that have multiple validations that could fail if the field is empty (e.g., an email address is required, but also fails a validity check). Assum...

Does asp.net MVC have Application variables?

I am busy converting a web application to MVC and have some information saved to Application variables used across multiple tenants/accounts to make things a bit more efficient. I realise the point of MVC is to keep things as stateless as possible, Sesion State obviously makes sense to have and exists in MVC but we dont want to just con...

How to test FormsAuthentication in a asp.net mvc 2.0 app with

Ive made a interface with the following methods: Public Interface IAuthenticationService Sub SetAuthentication(ByVal username As String) Sub Logout() Function IsLoggedIn() As Boolean End Interface My implementation looks like: Public Class Authentication Implements IAuthenticationService Public Sub Logout() Implem...

What type of ActionResult should I return from an MVC Action where I want javascript to either redirect or update a div?

Let me first outline my objective from a user's perspective and then the code I have to achieve that goal where its falling short. I'd like the user to be able to click a button, which brings up a jQuery modal style dialog with a few fields on it and a submit + cancel button. When they successfully commit the record I'd like to have the...

CSLA Not reporting object as dirty after being changed.

Hi, I've got a CSLA object that is returning data from the database fine but when I change any of the properties on the object the object still says IsDirty = "false". Although when I create a new object it reports IsDirty = "true". I'm sure its just something simple that I'm missing in my code. The following is my object: [Seriali...

Action Parameters Add a default value when No Key

How can I set up a default value in my Action Filter when an ActionParameter is empty? When I use the About and Area_1419 Actions on my controller the filter works fine as it picks up the passed SectionID parameter. When I use the index action I get the error below…. The given key was not present in the dictionary. On this line... var...

jQuery TreeView with ASP.NET MVC how to pass argument to url

Here's the problem: I'm trying to do an Active Directory Explorer with Asynch. jQuery TreeView. In standard ASP.NEt it was fairly easy with builtin TreeView and some events in code-behind. The problem is that I don't exactly know how can I pass different arguments depending on which treeview leaf is being expanded. Based on this exampl...

Good example / tutorial of adding and editing a data row in a lightbox using ASP.NET MVC?

Hi, Im looking for a good example or tutorial which demonstrates adding and editing a data row (presented in a HTML Table) in a light box using ASP.NET MVC? Many thanks ...

Cleanest way of updating many entities (of the same type) on one page with Entity Framework and ASP.NET MVC?

Lets pretend we have a /Cart/Checkout view that lists every Product in the Cart, plus a TextBox with the Quantity (in my real world application I have more than Quantity). How would you update the Quantity? I have used the following code, but I'am looking for a "cleaner" way of doing it. View <% int i = 0; foreach(var product in Model....

What the best way to handle server side tags inside of a js file?

I'm using Asp.NET MVC and have a huge dependency on JQuery throughout my entire application (not sure if that's important here or not). I'm trying to build a set of js library files to go along side my views. The problem that I'm faced with is that I need a way to manage the server side location of my files and action links for all of my...

ASP.net MVC CheckBoxFor casting error

I have a EF entity that is tied to a SQL table that contains a bit field called "Active". I generate the Edit code from the T4 template, and the page inherits from the EF entity. At the bottom of the page, it generated a CheckBoxFor like this: <%= Html.CheckBoxFor(model => model.Active) %> I get the wonderful red squiggly under mode...

ASP.NET MVC Google Sitemap from ContentResult - Incorrect namespace

I created a sitemap generated by a ContentResult however Google keeps telling me my namespace is incorrect. Any ideas? My Code: public ContentResult Index() { //Build RSS for sitemap XNamespace ns = "http://www.sitemaps.org/schemas/sitemap/0.9"; const string url = "http://www.openarmssoberliving.com/{0}"; ...

How to generate an XML file from an ASP.NET MVC view?

My main goal is to generate an XML file that can be downloaded. The below code succeeds in generating the file but the view (/Home/XmlView) can be accessed directly. If I use the [Authorize] attribute on the XmlView() method then the file is created with the HTML of my default logon page. How do get the authorization to work with the ...

Set MaxAllowedContentLength/maxRequestLength value per action.

How do I set maxAllowedContentLength value per action? I have a few actions that used to upload files, each one needs a different maxAllowedContentLength value. It make sense that we don't want to use action filters as we want to filter this request at IIS level. On the other hand, action filter is the best solution from coding perspec...

ASP.NET MVC Routes Login/Logout Problem

Hi Guys, Relatively new to ASP.NET MVC and little confused about how to do routing. My problem basically relates to "logged in" and "logged out routes" and having both as "/". i.e. I have home/index for logged out user which appears as "/" but this has got me confused as to how I can have home/home for logged in user and still have "/"...

Developing a new RESTful web service in .NET -- where should I begin? ASP.NET-MVC, WCF?

Exposition (short version at the bottom) The objective is to build a service that I will then consume via jQuery and a standards based web front-end, mobile device "fat-clients," and very likely a WPF desktop application. It seems like WCF would be a good option, but I've never built a RESTful service with WCF, so I'm not sure where to...