asp.net-mvc-2

ASP.NET MVC AJAX with HTML.ValidationMessageFor

风格不统一 提交于 2019-12-21 04:29:04
问题 I'm used to the ASP.NET Webforms easy way of doing AJAX with UpdatePanels. I understand the process is much more artisanal with MVC. In a specific case, I'm using Data Annotations to validate some form inputs. I use the HTML.ValidationMessageFor helper to show an error message. If I want to use AJAX to post this form and show this error message, what would be the process? Is it possible to keep the HTML.ValidationMessageFor and make it work with AJAX? Thank you. 回答1: This article might be

How can I add callbacks to jquery validation (when used in MVC 2)

ぐ巨炮叔叔 提交于 2019-12-21 04:13:21
问题 I'm using jquery for validation in my MVC2 web app (as described here) and I'd like to wire up some callbacks that the jquery validation plugin supports, like invalidHandler, etc. I can manually edit the MicrosoftMvcJQueryValidation.js and add my callbacks (in __MVC_EnableClientValidation, in the options variable) but I was looking for a better approach since that file is used repeatedly and I don't want to have to create one-off copies. A way to manually add an invalidHandler (etc) callback

How can I add callbacks to jquery validation (when used in MVC 2)

拜拜、爱过 提交于 2019-12-21 04:13:07
问题 I'm using jquery for validation in my MVC2 web app (as described here) and I'd like to wire up some callbacks that the jquery validation plugin supports, like invalidHandler, etc. I can manually edit the MicrosoftMvcJQueryValidation.js and add my callbacks (in __MVC_EnableClientValidation, in the options variable) but I was looking for a better approach since that file is used repeatedly and I don't want to have to create one-off copies. A way to manually add an invalidHandler (etc) callback

Generate a sequence of numbers [duplicate]

余生长醉 提交于 2019-12-21 04:04:59
问题 This question already has answers here : How to create a sequence of integers in C#? (6 answers) Closed 3 years ago . I want to create sequence numbers in asp.net mvc2.. Then number should start from { 0 to 1000} . I tried like following, var seq = Enumerable.Range(1, 1000); ViewData["OrderNo"] = seq; In view: <%:Html.Hidden("OrderNo") %> <%:ViewData["OrderNo"] %> My result is System.Linq.Enumerable+<RangeIterator>d__b8 But when getting value in view it is not working... How to generate

ASP.NET MVC redirect from attribute

梦想的初衷 提交于 2019-12-21 03:26:10
问题 I'm trying to execute a Redirect from a method attribute. It seems to work: public class MyAttribute: ActionFilterAttribute { [..] public override void OnActionExecuting(ActionExecutingContext filterContext) { [..] filterContext.HttpContext.Response.Redirect(urlToRedirectTo, true); [..] The only problem is that the redirect is executed after the end of the method it's attached to, while i'd like the redirect to prevent the execution of the method. Any help? Thanks 回答1: You can prevent

ASP.NET Data Caching? Memcache equivalent

爱⌒轻易说出口 提交于 2019-12-21 02:54:45
问题 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? 回答1: You can use memcached also. There are also other alternatives. You may also check Scott Gu's post about the new cache extensibility

How to extend AuthorizeAttribute and check the user's roles

怎甘沉沦 提交于 2019-12-21 02:44:50
问题 I am busy writing my own custom attribute for my action method called MyAuthorizeAttribute, I am still busy writing the code, here is my partial code: [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] public class MyAuthorizeAttribute : AuthorizeAttribute { public new Role Roles; public override void OnAuthorization(AuthorizationContext filterContext) { base.OnAuthorization(filterContext); if (Roles != 0) // Did it this way to see what the value of Roles was return; // Here I

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

我的梦境 提交于 2019-12-20 20:40:05
问题 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. 回答1: I found the solution myself on the internet.

Injecting AutoMapper dependencies using Ninject

天涯浪子 提交于 2019-12-20 20:00:13
问题 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

Attempting to add a strongly typed view does not find any classes in the MVC project

三世轮回 提交于 2019-12-20 18:43:35
问题 I have a very odd problem. Whenever I try to use the "Add View" dialog in ASP.NET MVC2 and then try to "Create a strongly-typed view" by selecting a "View data class" from the drop down of available classes none of the classes ("models") in my MVC project are showing up. The very odd part is all of the assemblies that my MVC project is referencing, even other projects in the solution, their classes are showing up. I have tried cleaning, rebuilding, cleaning the obj folder but every single