asp.net-mvc-2

LazyList<T> vs System.Lazy<List<T>> in ASP.NET MVC 2?

牧云@^-^@ 提交于 2019-12-02 23:29:17
In Rob Conery's Storefront series, Rob makes extensive use of the LazyList<..> construct to pull data from IQueryables . How does this differ from the System.Lazy<...> construct now available in .NET 4.0 (and perhaps earlier)? More depth based on DoctaJones' great answer: Would you recommend one over the other if I wanted to operate on IQueryable as a List<T> ? I'm assuming that since Lazy<T> is in the framework now, it is a safer bet for future support and maintainability? If I want to use a strong type instead of an anonymous ( var ) type would the following statements be functionally

ASP.NET MVC Authorize Attribute does a 302 redirect when the user is not authorized

大兔子大兔子 提交于 2019-12-02 23:09:21
MSDN explicitly says it should do 401 redirect, but I'm getting a 302 redirect on FF, and this is causing problems in AJAX requests as the returned status is 200 (from the redirected page). http://msdn.microsoft.com/en-us/library/system.web.mvc.authorizeattribute.aspx I've found someone else with the same problem: http://blog.nvise.com/?p=26 Any other solution, besides his? The Authorize attribute does return a Http 401 Unauthorized response. Unfortunately, however if you have FormsAuthentication enabled, the 401 is intercepted by the FormsAuthenticationModule which then performs a redirect to

How to correctly canonicalize a URL in an ASP.NET MVC application?

走远了吗. 提交于 2019-12-02 22:31:26
I'm trying to find a good general purpose way to canonicalize urls in an ASP.NET MVC 2 application. Here's what I've come up with so far: // Using an authorization filter because it is executed earlier than other filters public class CanonicalizeAttribute : AuthorizeAttribute { public bool ForceLowerCase { get;set; } public CanonicalizeAttribute() : base() { ForceLowerCase = true; } public override void OnAuthorization(AuthorizationContext filterContext) { RouteValueDictionary values = ExtractRouteValues(filterContext); string canonicalUrl = new UrlHelper(filterContext.RequestContext).RouteUrl

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

♀尐吖头ヾ 提交于 2019-12-02 22:06:33
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. 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 of there via the Response property. akky In mvc application you can use HttpContext.ApplicationInstance

How can I create a generic UniqueValidationAttribute in C# and DataAnnotation?

穿精又带淫゛_ 提交于 2019-12-02 21:27:32
I'm trying to create a UniqueAttribute using the System.ComponentModel.DataAnnotations.ValidationAttribute I want this to be generic as in I could pass the Linq DataContext, the table name, the field and validate if the incoming value is unique or not. Here is a non-compilable code fragment that I'm stuck at right now: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ComponentModel.DataAnnotations; using System.Data.Linq; using System.ComponentModel; namespace LinkDev.Innovation.Miscellaneous.Validation.Attributes { public class UniqueAttribute

ASP.NET-MVC 2 DataAnnotations StringLength

▼魔方 西西 提交于 2019-12-02 20:15:02
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? 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; } Use a regular expression attribute. These are interpreted on the client side as well. [RegularExpression(Regexes.MinStringLength)] public string MyText { get; set; } Where Regexes.MinStringLength is a static regular expression class. Inline

ASP.NET MVC 2.0 JsonRequestBehavior Global Setting

心不动则不痛 提交于 2019-12-02 20:04:55
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, contentType, JsonRequestBehavior.AllowGet); } This, like other MVC-specific settings, is not settable via

Using NServiceBus with Asp.Net MVC 2

依然范特西╮ 提交于 2019-12-02 18:55:16
Is there a way to using NServiceBus with Asp.Net MVC 2? I want to send a request message from a Asp.Net MVC2 Application to a Service, which handle the message and reply with a response message. is there a way to do this clearly? Udi Dahan If you really want to do this, here's how: var sync = Bus.Send<SomeMessage>(/*data*/) .Register((AsyncCallback)delegate(IAsyncResult ar) { var result = ar.AsyncState as CompletionResult; // do something with result.Messages }, null ); sync.AsyncWaitHandle.WaitOne(/*timeout*/); Andreas Öhlund There is a reason that NServiceBus only supports registering

ASP.NET MVC2 Linq Where Clause using StartsWith

◇◆丶佛笑我妖孽 提交于 2019-12-02 18:37:52
问题 I have a few filters on my view, the first one is list by first name, last name and company name when one of these options are selected the user can then select a, b, c ... x, y, z to show only people starting with the selected letter. if (collection["Filter"] == "2") { presentations = presentations.Where(x => x.Person.FirstName.StartsWith("A")); presentations = presentations.OrderBy(x => x.Person.FirstName); } Results returned are similar to John Squirel Basil Boywiz David Smith This doesn't

I need to add custom css to jquery tabs when it is selected, how?

穿精又带淫゛_ 提交于 2019-12-02 18:26:37
问题 I need to modify the css of .ui-state-active , .ui-widget-content .ui-state-active to the following: .ui-state-active , .ui-widget-content .ui-state-active { background-image: url('images/tab-over.png') !important; } However, when I do that I get the desired effect but other elements on the website get affected when clicked. I want this function only when I click a tab. Is there a safer way to do this ? Here is my html code: <div id="tabs"> <div id="left-side"> </div> <ul class="tab-menu">