asp.net-mvc

asp.net mvc how it decides which view to load

I am attempting to construct an asp.net mvc app which will use the urls like: /Controller/[Number]/Action/Id I have got it to always call my controller and pass it the Number and the Id fine... However I now want to return a different view depending on the Number I could have options like: if([Number] == 1) { return View("ViewName...

Visual Studio 2010 MVC Project type Disappeared

I have been working with visual studio 2010 Premium RTM for over a month. When I installed it I had a fresh install of windows. (No betas or previous versions of VS) I have been creating new ASP.NET MVC2 C# projects since I installed it. I went to create a new mvc project today and I don't have that as an option anymore. I went in unde...

how to put DisplayName on ErrorMessage format

Hello there, I have something like this: [DisplayName("First Name")] [Required(ErrorMessage="{0} is required.")] [StringLength(50, MinimumLength = 10, ErrorMessage="{0}'s length should be between {2} and {1}.")] public string Name { get; set; } I want to have the following output: First Name is required. First Na...

Update only part of a Model, validation problem?

Hi, I have a sign-up page where the user can input his FirstName, LastName, Email and Password, along with other fields. I have bound validation attributes to this Model (called "User" and created via LINQtoSQL) and all works well. Model code: [MetadataType(typeof(UserValidation))] public partial class User { } [Bind(Exclude = "User...

Controller side column binding for Telerik MVC Grid

I have a partial view that uses a Telerik MVC Grid, and it has column binding code as follows (very partial view): .Columns(column => { column.Bound(model => model.PlannedFinishDate).Title("Planned Date").Format("{0:dd/MM/yyyy}").Width(83); column.Bound(model => model.Province).Width(70); if (Roles.IsUserInRole("Controller")...

Browser capabilities redirect in asp.net mvc

I want to detect certain browsers (IE6) and redirect them to a page that tells them to get a better browser. Same thing for detection of Javascript being enabled, if the browser has it disabled I want to send them to a page which explains this fact. Is there an elegant or preferred way to do this in mvc? ...

Use reflection to to see if Controller is within an Area

How do use reflection to determine whether a Controller of a given type is within a Area in an ASP.net MVC project? I am trying to write a new ControllerTypeResolver for an MvcSiteMap and need to work out if the type I am resolving exists within an Area in or not. ...

How to initialize a javascript variable using Json String in Asp.net MVC?

I have the following Action method. public ActionResult Action() { var model = new SampleViewModel(); model.JsonString = ReadJsonStringFromSomewhere(); return ViewResult(model); } In my view I have the following method to initialize a javascript variable. <script type="text/javascript"> var jsObject = eval("(" + <%= Mod...

How to call a function *only once* in ASP.NET MVC page cycle

I have an ASP.NET MVC web app and have a function that I need to call when the page loads only once. Right now I have the function being called from a base controller OnActionExecuted. The issue I'm having is that this function is called multiple times - once for the page, and then multiple times for different ajax calls that I have on...

Entity Framework 4 Code Only Error "Multiple objects sets per type are not supported"

I have two "Code Only" POCO's using EF4 and the latest CTP, running against an existing, legacy database. Running a LINQ query against PocoA worked until I added a public virtual PocoB pocoB { get; set; } to PocoA. I was trying to add a relationship. Once I did that, I started getting the following error: Multiple object sets per typ...

MVC Validation and business layer

The DataAnnotations validation happens in the default model binder and most of the examples I've seen uses the Model.IsValid in the Controller to verify if a model is valid or not. Since my controller action calls a business layer method and I like to validate the entity there: Do I have to explicitly switch off the model binder valida...

ASP.NET MVC model binding for IEnumerable<string> that can change model?

My view model has the property: public IEnumerable<string> Names { get; set; } My view displays that information using a simple markup that renders to: <div id="names"> <ul> <li>Name1<img src="/delete.png"/></li> <li>Name2<img src="/delete.png"/></li> <li>Name3<img src="/delete.png"/></li> </ul> </div>...

ASP.NET MVC's AsyncController and Session data

We have a somewhat complex and long-running action method for which we'd like to show a progress bar. The javascript grid that we're using requires that saving and loading data be done in a single request (save first then load), and also requires us saving data to session. Our initial thought was to just use an AsyncController, but the...

Match both www.website.com and website.com with sql like

I have a table that contains a list of websites. I have a sql variable @url, I want to select all the rows where the website is equal to @url. However, if there is no subdomain I want to match www and the root domain. So, if @url='http://website.com' it should match both 'http://website.com' and 'http://www.website.com' I'm currentl...

ASP.NET Membership Alternatives

I have always stayed away from asp.net membership as it seemed bloated, and (at the time) untestable. In the case of asp.net MVC specifically, does anyone use an alternative solution for assigning roles to users, and storing some addition information for the logged in user? Any recommendation? Is it crazy to just roll your own, just impl...

ASP.NET MVC helper for accessing Gravatar images

Whilst the Gravatar service's API (well, it's really just a URL) is pretty straightforward, is there a simple helper method out there that does a good job of reflecting all the options available for Gravatar? Image size Default image (when user hasn't specified one) Rating (G/PG/R/X) Ideally this would be an HtmlHelper extension meth...

is a background worker in a controller async?

Inside an asp.net mvc 2 controller, I have the following code: using (BackgroundWorker worker = new BackgroundWorker()) { worker.DoWork += new DoWorkEventHandler(blah); worker.RunWorkerAsync(var); } My question is: is this code asyn...

MVC Beginner Question

Hi All, Im just starting to make my first ever asp MVC website. Im just wanting advice on 3rd party controls that I could utilize to make the job a bit easier. The graphics designer has done all work in photoshop (logos, layout prototypes etc) which i will have to translate to the webpage. While its not a graphics intense website there...

ASP.Net MVC2 - IIS7.5 doesn't find view file for home page

We have a mid-sized asp.net project that we just promoted from our dev server (Windows 2003) to an external test server (Windows 2008 R2). On the test server, IIS is not finding our home page, which is located in the views/home folder (404 error). As far as we can tell, the settings are the same on both servers. I've confirmed HTTP ...

controller used to save data, have it return view() instantly and run code in the background

I have a controller whose main function is to save data. The ajax call that saves this data needs to be executed quickly. What I want to do is get the POST in the controller and spin off a background thread that will do the actual work to save the data; this would allow me to do return view() instantly. So essentially the only lag it w...