asp.net-mvc

asp.net mvc Html.Listbox - how to add an item manually

I am looking for a way to manually add items to html.ListBox in mvc. I want the top item to be "All Items". i.e. All Items Item1 Item2 Item3 I am currently calling: <%=Html.ListBox("items", Model.Items, new { style = "height:50px;width:100%" })%> I may have to add it in the model when setting up the MultiSelectList, but would be pr...

How do I test a controller that has an Authorize attribute and dependencies injection by IoC?

Hi I’ve taken over an ASP.NET MVC project from a colleague. I have only a rudimentary knowledge of both ASP.NET MVC and unit testing. I’m trying to get off on the right foot by creating unit tests. I thought I’d start with testing a controller. Unfortunately I stumbled at the first hurdle! The controller in question has the Authorize ...

How to bind form fields to model properties with different names?

Hello. I've got a search form that I want to use short query string parameters for (e.g. ?q=value&s=whatever&c=blah) and I'd like to use MVC model binding to get those parameters into my controller action. I can create a type that mirrors these short names, but I'd rather have a type that has more sensible names (e.g. q = Query, s = Sor...

Do we only test the Contoller classes in an ASP.Net MVC application?

I guess the title says it all. I want to do this web application I am creating in the best possible way. All the unit testing examples I have come across are for contollers only. I understand the views would be quite hard to test and perhaps the model layer would need something like DBUNit. What are your thoughts? ...

ASP.NET MVC: How to add a library via the using command

I am trying to load generics within the aspx page. Here is my code <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %> <div id="CategorySelectBoxes"> <% //this has syntax error using System.Collections.Generic; //get parentid list category c = new category(); is there a way to load the generic l...

Creating ViewResults outside of Controllers in ASP.NET MVC

Several of my controller actions have a standard set of failure-handling behavior. In general, I want to: Load an object based on the Route Data (IDs and the like) If the Route Data does not point to a valid object (ex: through URL hacking) then inform the user of the problem and return an HTTP 404 Not Found Validate that the current...

Asp.net MVC2 Deployment: Directory Listing Denied

I have created an Asp.net MVC2 application in VS2008. When i am running the website on internal server its working fine. But when i created a virtual directory for the website on local IIS6, its giving me error Directory Listing Denied This Virtual Directory does not allow contents to be listed. How can i deploy the asp.net MVC site on...

Handling mvc security...override membership provider, action filter, or something else? Not sure how to handle this.

I'm at a point where I'm really confused about how to go about handling security in my ASP .NET MVC application. Here's what I know I want to do: 1) I want my own schema layout so I can implement security how I want it and not be tied to Microsoft's default db schema (which I've seen next to no support for on other dbms's). 2) This is ...

MVC 2.0:How to send simple TextBox value to Action with an ActionLink?

Basically, i don't want to use <input type="submit"> mainly because it's a button, i'd rather user ActionLink, so i am using Ajax.ActionLink, and i'm not sure what to place in the routeValues argument for it to pickup the new (edited) data (user enters comments etc) and send it to my action. would any of you know? thanks. this is what i...

Data Annotation validation messages are not localized when UICulture is changed in an ActionFilter

The reason seems simple enough: model binding (and therefore validation) happens before the earliest ActionFilter method (OnActionExecuting) is executed, therefore changing UICulture has no affect on validation messages. Is there an earlier integration point (besides an IHttpModule) that I could use here? I'd rather an Attribute-based ...

How to achieve Import/Export on button click from grid view to excel sheet using asp.net mvc

Hello friends, I have a gridview with data. I need to put one button to Export/import that gridview data to excel sheet using asp.net mvc. Can anybody help me out how to do this. Thanks. ...

unit testing asp mvc view

How can i unit test the view of an ASP MVC application? I have tried the mvc contrib test helper... _controller.Index().AssertViewRendered(); but this doesn't actually test the view. for example i can happily insert some bogus code in the view, and get the dreaded yellow screen of death, without my unit test ever knowing about it. ...

C# ASP.net MVC database questions

I am trying to develop a website with C# ASP.net MVC. It's my first time using Visual Studio, C# and ASP.net so I have lots to learn but so far so good. So far... I started a C# ASP.net MVC project and added a database by going to the Database Explorer and clicking "add connection". I then did some standard CRUD controllers and views. I...

asp.net mvc editing the auto templates TT

hi. im using dataAnnotation and meta data for my model classes all all is good however i dont like that it creates an untidy form, and would rather it comes out in a nice table i have set a style for so i have labels next to my inputs etc. now there was a post somewhere that they are created from TT files and that you can set MVC to ru...

How can I get the post or get state inside the htmlHelper in ASP.NET MVC?

Hi, I am trying to get whether it is a post or get in the htmlhelper as i am building an validationsummary extension and I only want it to run when the form is posted? Any ideas? currently what I've got is this and it works well but it runs every time the page is loaded StringBuilder sb = new StringBuilder(); sb.Append("<scr...

How can i pass two different query string params that represent one action method param?

Hi folks, i've got an action method like the following public JsonResult Index(string version) { .. do stuff, return some data v1 or v2. Default = v2. } So, this action method returns some data, which can be formatted either as Version 1 or Version 2 (whatever output that is ... just know that they are schemantically different). ...

What's the difference in ASP.NET MVC of RedirectToRoute and RedirectToAction?

What's the difference in ASP.NET MVC of RedirectToRoute and RedirectToAction? It's not clear what the difference is to me. ...

The model item passed into the dictionary is of type ‘mvc.Models.ModelA’ but this dictionary requires a model item of type ‘mvc.Models.ModelB‘

I have this annoying mistake in some of my builds. There is no error in the project, because if I build again, then the problem disappears. The message only appears, when the site is deployed to a Windows 2008 Server. I first thought that it might be an issue with temporary files, but thats not the case. I deployed the build to a di...

Adopting the "aspnet_ ..." sql tables from ASP.NET MVC

Hi everyone, I'm just starting a new project on ASP.NET MVC and this will be the first project actually using this technology. As I created my new project with Visual Studio 2010, it created to my sql server a bunch of tables with "aspnet_" prefix. Part of them deal with the built-in user accounts and permission support. Now, I want t...

Strongly-typed or weakly-typed binding in codebehind in front end?

So my question is more in relation to what people consider to be the best practice and why: I've been dropping literals into pages and repeaters and binding them in code behind for a while. Is this considered bad practice? ie: ASPX Page: <asp: Literal id="litTextToInsert" runat="Server" /> Code Behind: litTextToInsert.Text = objDat...