asp.net-mvc-2

.spark views get copied to /bin/Views - why?

Building or publishing my ASP.MVC 2 application the .spark files in the View directories copied to /bin/Views/*. This redundancy seems to be useless as the app runs fine on the server even if I delete the bin/Views directory. Any idea how to prevent this behavior? My files are tagged with the default build action "Content" and the Vi...

How can we set authorization for a whole area in ASP.NET MVC?

I've an Admin area and I want only Admins to enter the area. I considered adding the Authorized attribute to every controller in the Admin area. Isn't there an elegant solution or is this feature not there in the framework itself? EDIT: I'm sorry, I should to have mentioned this before. I'm using a custom AuthorizedAttribute derived fro...

Deploying Asp.Net MVC 2 /C# 4.0 application on IIS 6

Hi, I got a problem migrating from VS.Net 2008 / MVC 1 to VS.NET 2010 (+C# 4.0) / MVC 2 The web.config has been updated, the site runs well in Cassini, but my problem now is deploying on IIS 6. I updated the web site to run using ASP.Net 4, but whatever URL I try, I always have a 404 error. It's as if the routing was not taken into ac...

special html characters are not rendered correctly in the browser

I am storing pieces of XHTML as text on a search index. Once the user submits a search request, I insert this text in my page and return it to the server. This all works fine except when there is a ISO 8859-1 Symbol in the text (such as a copyright symbol ©). The symbol is not represented correctly in the browser, it is displayed as t...

MVC.net + subsonic Auto Generate MetaData Classes from TT

hiya Not a question but i dont have a blog and i have just created a new subsonic TT file that will generate the Metadata classes automatically for the subsonic classes so you can skip out some work when using dataAnnotation and CreateForModel etc so the first step is to amend your ActiveRecord.TT with the following using System.Com...

.NET MVC : Calling RedirectToAction passing a model?

I got a view List.aspx that is bound to the class Kindergarten In the controller: public ActionResult List(int Id) { Kindergarten k = (from k1 in _kindergartensRepository.Kindergartens where k1.Id == Id select k1).First(); return View(k); } That works. But this doesn't [AcceptVerbs(HttpV...

mvc 2.0 validation

I am use DataAnnotations validation, it work perfectly but when I validate empty text box field I have error The value '' is invalid how can I customize this error? p.s. error shows only when clients script are off ...

LinkBuilder.BuildUrlFromExpression not working anymore in .Net 4 / VS 2010 ?

Hi, I recently migrating my ASP.Net MVC 1 application from VS.Net 2008 / C# 3.5 to VS.NET 2010 / C# 4.0. I massively used a builder to get URL strings from the strongly typed calls. It looks like this : // sample call : string toSamplePage = Url.To<SampleController>(c => c.Page(parameter1, parameter2)); the code is added as an exten...

MVC 2, IModelBinder & ValueProvider changes

Hi, I'm trying to migrate to ASP.Net MVC 2 and meet some issues. Here is one : I needed to bind directly a Dictionary as result of a view post. In ASP.Net MVC 1 it worked perfectly using a custom IModelBinder : /// <summary> /// Bind Dictionary<int, int> /// /// convention : <elm name="modelName_key" value="value"></elm> /// </summar...

Custom form authentication / Authorization scheme in ASP.net MVC

I am trying to create a custom authentication scheme in ASP.NET MVC using form authentication. The idea that I might have different areas on the site that will be managed - approver are and general user area, and these will use different login pages, and so forth. So this is what I want to happen. User access restricted page (right now...

MVC2 Checkbox problem...

When I used the html Helper Checkbox, it produces 2 form elements. I understand why this is, and I have no problem with it except: The un-checking of the checkbox does not seem to be in sync with the 'hidden' value. What I mean is that when I have a bunch of checkboxes being generated in a loop: <%=Html.CheckBox("model.MarketCategori...

ASp.net MVC 2 changed how tryupdatemodel works, what is the easiest way to fix my code?

I initialize my strings to blank, not null. Which worked fine in MVC 1, using tryupdatemodel in that any text entries that had no text in them would be set to a blank string, in MVC 2 RC2 apparently (at least from my testing) it sets them to null / nothing. So now I'm getting errors from my validation layer which requires those to be bla...

Why it's not a good idea to pass entities as Models in MVC?

We're developing a pretty large application with MVC 2 RC2 and we've received some feedback on the way we're using the Entity Framework's Lazy Loading. We're just getting the entities in the controller and sending them as models to the Views, that is causing that the view code asks the Database for the navigation properties we are usin...

Generating Data Annotations from Generated Classes

I have a linq to sql object or if neccessary Entity Framework object. I want to do MVC 2 Data Annotations for them, but I am endlessly lazy. Is there a way to automatically generate the data annotations a-la [Bind(Include = "Title,Description,EventDate,Address,Country,ContactPhone,Latitude,Longitude")] [MetadataType(typeof(Dinner_Val...

How to update custom ModelBinder to work with altered ModelBindingContext.ValueProvider interface in ASP.NET MVC RC2

I have a custom model binder that takes a comma separated list and cleans out any empty values, then passes it along to the default model binder. This worked in ASP.NET MVC Preview 2, but when I upgraded to RC2, the below won't compile because the interface of ValueProvider only has a GetValue() method, no [] accessor. Is what I'm doing ...

Should I keep working on my project on MVC 1.0 or stop and learn MVC 2.0?

Hello, Few months I've started learning ASP.NET MVC 1.0. Although hard in the beginning, now I've made huge progress so that I'm working on something serious I can show to my colleagues. But, now MVC 2 is almost out there. Now I would like to know if MVC 1.0 and MVC 2 are profoundly different. In fact, I wonder if I need (first) to fi...

Is there a way to have the DefaultModelBinder ignore empty items when binding to a List<Enum>

I have a scenario where I'd like to change the behavior of the DefaultModelBinder in how it binds to a List of enums. I have an enum... public enum MyEnum { FirstVal, SecondVal, ThirdVal } and a class for a model... public class MyModel { public List<MyEnum> MyEnums { get; set; } } and the POST body is... MyEnums=&MyEnums=Thi...

GetControllerInstances type is null

Hello, Try to ASP.NET MVC 2 Areas and have a problem. I have a User Area and a Blog area. User area is working properly but when I use my Blog area the controllerType is null in my GetControllerInstance. I have not made any changes in my areas so everything is as it was when I created them. I Have also tried to add a test area with name ...

Windows Azure Subdomain Re-Routing with ASP.NET MVC

I have the following issue, lets say I create an A record with my domain like *.mydomain.com, my main domain has a CNAME record pointing to my Windows Azure given domain name. So it goes as follows: A record: *.mydomain.com 127.0.0.1 CNAME record: mydomain.com myservice.cloudapp.net Now I want the ability to control custom subdomain i...

ASP.NET MVC2 - Custom Model Binder Examples

I am trying to find some examples of building a custom model binder for a unique binding scenario I need to handle, but all of the articles I found were for older versions of MVC which are no longer relevant in MVC2. I've been referencing the DefaultModelBinder source code to try to get a general feel for what I need to do, but it's enti...