asp.net-mvc

How to prepare the controllers to use Session but be testable?

How to prepare the ASP.NET MVC Controllers to use Session and at the same time be testable, so in essence not use Session but rather use some Session abstraction? I am using Ninject so your examples could be based on that. The problem is that the Session object is not available at all times in the controllers (like in ctor's) but I need...

Routing goes nuts on asp .net mvc 2 application that is the same app set up 2x on the same server.

This is going to sound quite bizarre. I have one ASP .NET MVC 2 application. Works great. Routing is not very complicated. I am running this on windows 2003 IIS 6, so I have to use the {controller}.aspx routing configuration. Anyhow, I've set the same MVC 2 application up twice under different virtual directories on IIS. This is litera...

Disable Model Validation in Asp.Net MVC

Hello, How do I disable Model validation for a single Action in a Controller ? Or can I do it per model by registering the model type at startup somewhere ? I want the ModelBinder to bind to the model, but afterwards it should not perform the model validation. The reason why i dont want validation to happen is because i am trying to m...

dropdownlist issue

I have a dropdownlist generated from db. Here is the result from page source. <select id="testList" name="testList"> <option value="0"></option> <option value="0">A</option> <option value="1">B</option> </select> Does anyone know why the empty is still zero? How come I dont get something like "" for the first one since it's empty? <d...

populating db frm rss xml

I want to read rss from different sources and populate them in the database (sqlserver 2008). I'm planning to store the content of rss.xml in one table and the master information like the version and deep link of the rss in another table. I haven't worked in xml before and couldn't find a better solution till now... help anybody... ...

format int to phone number

Is there a way I can format for example: 0000000000 into (000)000-0000? I'm returning a listbox which holds a collection of phone number which arent formated yet. What I would like is format it. This is what I have in the View: <%= Html.ListBox("phoneList")%> and from the controller: ViewData["phoneList"] = new SelectList(phoneList)...

ASP.NET MVC Custom HttpHandler

I'm follow this tutorial to use CAPTCHA in MVC application: http://coderjournal.com/2008/03/actionfilterattribute-aspnet-mvc-captcha/ I think this was made to ealry versions of ASP.NET MVC,because it doenst work for me. Problem is that captcha image never shows,cause the custom handler (captcha.ashx) never gets the request. In web.con...

Configuring ASP.NET application to always accept GET request from a particular IP address?

I have an application that's locked down using forms authentication. There are few nightly tasks I want to script that make get requests to, say, http://myapp.domain.com/NightlyTask ... I don't need any response, I just need it to accept a get request from a certain IP address. I realize you could spoof an IP address, etc. but I'm trying...

FileResult returning corrupt file

I'm creating a simple controller action in ASP.NET MVC 2 (under the .NET 4.0 framework) which will resize files. I've got a controller like this (I've cut it down a bit): public ActionResult GetFile(int fileId, string fileSource) { FileInfo file = repo.FindFileById(fileId); //do some resizing string mimeType = string.Empt...

DevExpress MVC .net 4

Hi All, Im just wondering if anyone has used DevExpress's MVC Extension controls successfully on .net framework 4.0 MVC 2? All reference I see to the product seem to only support 3.5. Thanks ...

StructureMap singletons varying by argument?

Using StructureMap, is it possible to have a singleton object for each value of an argument? For example, say I want to maintain a different singleton for each website in a multi-tenancy web app: For<ISiteSettings>().Singleton().Use<SiteSettings>(); I want to maintain a different singleton object corresponding to each site: ObjectFac...

how to implement mvc pagination view

Hello all, Could you show me please the best methode to make pager fpr my asp.net mvc view? I have a typical table with posts, and they will be all showed at one time. If I have a 30 entries, i will preffer to show just 6 at the time. It will greate if I will have something like a menu to navigate ( like 1 - 2 - 3 ). It can be server si...

Is there a way to set convention when returning a partial view

Is there a way to set convention when returning a partial view? For example: I have the following: HomeController ---> Home(action Method) --> _Home.ascx (partial view) AboutController ---> About(action Method) --> _About.ascx (partial view) I'm currently passing the partial view name explicitly to the PartialView helper(ie return P...

Asp.net mvc, validation error msg

How does asp.net mvc figures out validation error message for particular field? I got class with 3 fields where one of them is with type DateTime. When i post form and no data are provided for DateTime field and it is marked as Required, validation summary can't figure out field name and shows "A value is required" instead of expected "...

asp.net mvc c# - property EntryList of ViewData class..

I dont know where is my problem to access EntryList in ViewData. <%= Html.RenderPartial("LogOnControl", new NISE.Web.TestForum.Views.Shared.PaginationViewData() { PageIndex = ViewData.*EntryList*.PageIndex, TotalPages = ViewData.*EntryList*.TotalPages, PageActionLink = Url.Action("List","Entry", new { category = Vi...

asp.net mvc: binding complex objects

consider classic example: Product and Category editing Product in dropdown Id of Category is selected - Category mapped as object with all fields empty except Id when submitting Product edit form - validation gives an error: "Category name is required" (I have Required attribute on Category Name property) How deal with such errors if ...

Validate a model in viewmodel?

Hi. I wonder if there is a way to validate just one of my models in the viewmodel send it to my action? I use the DataAnnotations as validate rules. Like the if (!ModelState.IsValid) let me know if the question is unclear and I will edit for a better explination EDIT my viewmodel looks like this public class CompaniesViewModel { ...

Convert DateTime to Date

Code: <% foreach (var item in Model) { %> <td> <%= Html.Encode(item.BirthDate) %> </td> <% } %> display this: 8/24/2009 12:00:00 AM but I need only date (8/24/2009). It is possible to do without any formating in controller action ...

Special methods and tricks in ASP.NET MVC?

Please tell me your favorite trick and tips to me. I want to collect so much knowledge as I can. And I think it's the best way to hear it from experts and amateur developers. *1. HTML FORM Tag + Attribute "multipart/form-data" and HttpPostedFileBase * I cloud tell you something about html form tag. If you use form tag in MasterPage of...

format property in class to return phone number

Is it possible to format what I have below to return a phone number? private string _Phone; [DataMember] public string Value { get { return String.Format("{0:(###) ###-####}", Int64.Parse(_Phone)); } set { _Phone = value; } } ...