asp.net-mvc-2

Strange behaviour in ASP.NET MVC: removing item from a list in a nested structure always removes the last item

混江龙づ霸主 提交于 2019-12-03 09:01:34
Scenario I have a parent/child model (to be exact a small questionnaire form and a one or more number of contacts). For historic reasons, all of this would have been done on the same form so user would have a form for the parent and one child and they would hit a button to add more children. Child has a few standard fields and the same with the parent, nothing fancy. Main requirement is that the data must not touch the database until all is valid and setup while I would have to go back to server for adding deleting children. Implementation It was very quick to get this working in ASP.NET MVC

ASP.NET Data Caching? Memcache equivalent

梦想与她 提交于 2019-12-03 08:52:04
Having used PHP on Linux a lot, I'm used to using memcache so that the database doesnt have to be accessed on every single request. What do people use on Windows the achieve this? From the asp.net mvc applications which I've seen, none of them use any sort of cache, they just hit the database on every request? Is this common, and if so, why is it acceptable? Darin Dimitrov You can use memcached also. There are also other alternatives . You may also check Scott Gu's post about the new cache extensibility model introduced in ASP.NET 4.0. There is a Memcache equivalent for ASP.NET, it is

How can I get a reference to an HttpResponse in ASP.NET MVC?

佐手、 提交于 2019-12-03 08:22:12
问题 I'm calling a third-party library that takes a System.Web.HttpResponse . I see I have a HttpResponseBase , but not HttpResponse like in web forms. Is there a way to get the HttpResponse ? Using MVC 3 . [Edit] : I'm trying to do this in a controller method. Also corrected casing. 回答1: If you need to interact with systems which take the non-mockable types, you can get access to the current HttpContext via the static property System.Web.HttpContext.Current . The HttpResponse is just hanging off

Post array in ASP.NET MVC 2 using name=“array_name[]” for form elements

我的未来我决定 提交于 2019-12-03 07:17:38
Good day! In PHP it is possible to assign name attribute to input elements with square brackets, like this: name="my_value[]" and PHP automagically converts this to array on server side. Is this possible in ASP.NET MVC? If not is there any alternative to process a bunch of checkboxes in ASP.NET MVC? Thanks in advance! Yes, it is possible. You might take a look at the following blog post about the convention used by the default model binder. Make sure the name is still the same, but go ahead and remove the brackets. You can then add the values to an array like so: string[] values = Request.Form

Injecting AutoMapper dependencies using Ninject

左心房为你撑大大i 提交于 2019-12-03 07:08:43
I am having trouble injecting AutoMapper into an ASP.NET MVC 2 application using Ninject. I used Jimmy Bogard's post on AutoMapper and StructureMap type Configuration as a guide. public class AutoMapperModule : NinjectModule { public override void Load() { Bind<ITypeMapFactory>().To<TypeMapFactory>(); Bind<Configuration>().ToSelf().InSingletonScope().WithConstructorArgument("mapper", MapperRegistry.AllMappers); Bind<IConfiguration>().To<Configuration>(); Bind<IConfigurationProvider>().To<Configuration>(); Bind<IMappingEngine>().To<MappingEngine>(); } } Ninject throws an exception when

ASP.NET MVC 2 VirtualPathProvider GetFile every time for every request

断了今生、忘了曾经 提交于 2019-12-03 06:49:55
I have implemented a VirtualPathProvider. The VirtualPathProvider reads the view from File system. However my problem is the method GetFile(string virtualPath) is not executed every time for every request. I think it is related to the caching, isn't it? What I want is getting file every time for every request . Because for some cases, the page in the file system will be modified and users want the system shows the changes immediately. Thanks. I found the solution myself on the internet. Really thanks jbeall replied on 07-15-2008, 11:05 AM. http://forums.asp.net/t/1289756.aspx In short words,

Using a CSS File for site localization

◇◆丶佛笑我妖孽 提交于 2019-12-03 06:48:17
I'm creating a website with ASP.net MVC 2.0 which uses two different languages (English and Persian). I want to have two different layouts for these languages, English has a left to right and Persian has a right to left layout. What came to my mind was, if I could have two different css files, like when you do it with string or image localization will do the work for the site, the problem is I need to know how to do this! Any other suggestions on how to perform this would be helpful. You can read about: (W3C) Internationalization Best Practices: Specifying Language in XHTML & HTML Content ,

How to get the content/type of a file at runtime

血红的双手。 提交于 2019-12-03 06:47:57
问题 I am trying to determine dynamically the content/type of a input file. If I would be in a windows application I could write code like this (from this blog) private string GetContentType(string fileName) { string contentType = "application/octetstream"; string ext = System.IO.Path.GetExtension(fileName).ToLower(); Microsoft.Win32.RegistryKey registryKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext); if (registryKey != null && registryKey.GetValue("Content Type") != null) contentType =

ASP.NET-MVC 2 DataAnnotations StringLength

ⅰ亾dé卋堺 提交于 2019-12-03 06:36:41
问题 Can I use the MVC 2 DataAnnotations to specify a minimum length for a string field? Has anyone done this or have they created custom attributes and if so do you mind sharing the source? 回答1: If you're using asp.net 4.0, you can use the StringLength attribute to specify a minimum length. Eg: [StringLength(50, MinimumLength=1)] public string MyText { get; set; } 回答2: Use a regular expression attribute. These are interpreted on the client side as well. [RegularExpression(Regexes.MinStringLength)

ASP.NET MVC 2.0 JsonRequestBehavior Global Setting

不打扰是莪最后的温柔 提交于 2019-12-03 06:30:08
问题 ASP.NET MVC 2.0 will now, by default, throw an exception when an action attempts to return JSON in response to a GET request. I know this can be overridden on a method by method basis by using JsonRequestBehavior.AllowGet, but is it possible to set on a controller or higher basis (possibly the web.config)? Update: Per Levi's comment, this is what I ended up using- protected override JsonResult Json(object data, string contentType, System.Text.Encoding contentEncoding) { return Json(data,