asp.net-mvc-2

Can't use strongly typed parameters for dropdownlist in asp.net MVC

I have a DropDownlist that prompts a user for the State, when the user selects a state, ie. Colorado, it saves 'CO' in the database, works great. When the user goes back to the page, it shows 'CO' in the dropdown, but when the page posts back, the dropdownlist value is null. If I manually select a State again, posts back with the corre...

routing webform in asp.net mvc

I have an ASP.NET MVC app and I have a WebForm page I built in the MVC due to a tutorial on how to do something I needed to do, but it was all in WebForm style. Ive tried to figure out how to do the same thing in MVC format but cant figure it out. So I was needing to figure out how to use this page in my MVC app. But when I try to go to ...

How to populate a DropDownList in ASP.Net MVC2?

I have the following database schema: Here's how I populate a DropDownList in my AreaController.cs: public ActionResult Edit(int id) { Area area = areaRepository.GetArea(id); JefeRepository jefe = new JefeRepository(); ViewData["Jefes"] = new SelectList(jefe.FindAllJefes().ToList(), "ID", "Nombre", area.Jefe.Nombre); r...

Best practices for building links in MVC

If I do not want to do this in my View Markup, <%=Html.RouteLink("Listings", "Listings", new {market = "Austin", state = "Texas", pagenumber = 3 })%> what would be the best approach to creating links in MVC 2? I have a HTML helper to build a custom link but all it is doing is acting as a wrapper around RouteLink (or ActionLink). ...

Remember Me problem in ASP.NET MVC 2

Greetings. I have a problem with Remember Me possibility. It didn't remember my login. First of all I checked FormsAuthentication.SetAuthCookie( userName, createPersistentCookie ); in SignIn method. The second parameter is true if I checkbox is cheked. Also I've checked the cookie named .ASPXAUTH ( http://img412.imageshack.us/img412/3585...

How to construct HttpPostedFileBase?

I have to write a Unit test for this method but I am unable to construct HttpPostedFileBase... When I run the method from the browser, it works well but I really need an autoamted unit test for that. So my question is: how do I construct HttpPosterFileBase in order to pass a file to HttpPostedFileBase. Thanks. public ActionResult ...

How can I validate a model in MVC2?

I'm following the MVC2 NerdDinner tutorial and I can't make heads or tails of the model validation area. I have an Area class created by my .dbml. Then I created a partial Area class myself and added: partial void OnValidate(ChangeAction action) { if (!IsValid) throw new ApplicationException("Rule violations prevent saving"); }...

Best way to implement localization in asp.net mvc 2

Hi. I am converting a webforms app to mvc. I implemented localization in webforms this way: The user selects the language, which BTW can be an rtl language, and the selection goes into the user profile in order for it to persist the next time the user visits the site. I used anonymous profiles. also, I used resource files. The db table...

EF4 many-to-many navigation property is empty

Using the model-first approach, I made 2 entities: Project and User. A project has multiple Users (involved in the project), and a User has (access to) multiple Projects, so following along with the Tekpub video, I made the many-to-many navigation property using the primary keys of the two entities. I made some test data, and the data ...

RenderAction from OtherArea in MVC 2.0

How Can i use renderaction to render an action from inner Area in ASP.NET MVC 2.0? ...

Access "Application" object in ASP.Net MVC to store application wide variables

Hi, How do I store a variable or object application wide in ASP.net MVC. In regular ASP, you had the Application object, and in ASP.net too apparently. I'm using ASP.net MVC 2. Thanks! Yvan ...

Sending collection of items in ASP.NET MVC

Hello all! I've got two classes in my MVC project Order and Product. Because Product can be ordered many times and Order can have many products I've got third entity which is OrderedProduct. It joins those two entities in many-to-many relation. Now what I'm trying to do is to let user to make an order by putting products from the drop...

ASP.NET MVC - How to throw a 404 page similar to that on StackOverflow.

I've currently got a BaseController class that inherits from System.Web.Mvc.Controller. On that class I have the HandleError Attribute that redirects users to the "500 - Oops, we screwed up" page. This is currently working as expected. THIS WORKS <HandleError()> _ Public Class BaseController : Inherits System.Web.Mvc.Controller ''...

ASP.NET - ResourceNotFoundException is Undefined

I'm working through some Error stuff, and I've tried converting Richard Dingwall's example over to VB.NET. The problem is that I'm getting an error: Type ResourceNotFoundException is undefined '<AttributeUsage(AttributeTargets.[Class] Or AttributeTargets.Method, Inherited:=True, AllowMultiple:=False)> _' Public NotInheritable Class...

ASP.NET MVC - Use Reflection to find if a Controller Exists

I'm having a heck of a time figuring out how to properly implement my 404 redirecting. If I use the following <HandleError()> _ Public Class BaseController : Inherits System.Web.Mvc.Controller ''# do stuff End Class Then any unhandled error on the page will load up the "Error" view which works great. http://example.com/user/999 (whe...

asp.net mvc routing to a custom handler instead of controller?

I have a custom handler I've written that executes a custom action based on a parameter, for example: /action/option1 would execute the action handler with option1. I can have any number of options for the parameter... however this action is a custom handler, NOT an mvc controller, because I'm returning a plain text (possibly moving t...

My extension method isn't registering.

I'm following Pro ASP.Net MVC2 book and literally 90% of everything is new to me. I feel like a kid in a candy store! :) Unit testing, dependancy injection, and other things are really new and very foreign to the typical CRUD applications I create. Now I'm having trouble with a test the book asks us to design. [Test] public vo...

What is the proper way of using DTOs in this case?

I have the following domain class: public class Product { public virtual Guid Id { get; set; } public virtual string Name { get; set; } public virtual IList<Product> RelatedProducts { get; set; } } I have the following DTO class: public class ProductDTO { public ProductDTO(Product product) { Id = product.I...

Visual Studio Professional 2010: Stop "new {" from autocompleting into "new object {" (C#)

In Visual Studio Professional 2010 whenever I type the following: new { It automatically changes to: new object { Is there a way to make it not do this? "Object" does not have the properties of the object I want to anonymously create. ...

Visual studio crashes as soon as I open aspx or ascx View from MVC 2.0 project

Hello, Visual studio crashes as soon as I open aspx or ascx View from MVC 2.0 project. If I delete all bin and obj folders from projects, I can open aspx and ascx View page. But it crashes again after compiling. It started to crash after I moved strong typed model to different project. I got stuck and cannot go further, really frustrat...