asp.net-mvc-2

Default resource for data annotations in ASP.NET MVC

走远了吗. 提交于 2019-11-28 21:17:50
问题 There's a way to set the default resource to the data annotations validations? I don't wanna make something like this: [Required(ErrorMessage="Name required.", ErrorMessageResourceType=typeof(CustomDataAnnotationsResources)] public string Name { get; set; } I would like something like this: Global.asax DataAnnotations.DefaultResources = typeof(CustomDataAnnotationsResources); then [Required] public string Name { get; set; } someone gimme a light! thanks in advance EDIT My real problem was

MVC 3 Editor Template with DateTime

…衆ロ難τιáo~ 提交于 2019-11-28 21:15:29
I want to change this code from MVC2 <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.DateTime?>" %> <%=Html.TextBox("", (Model.HasValue ? Model.Value.ToShortDateString() : string.Empty), new { @class = "datePicker" }) %> To MVC 3 using Razor. You can find the full post of what I want to do here @model DateTime? @Html.TextBox("", (Model.HasValue ? Model.Value.ToShortDateString() : string.Empty), new { @class = "datePicker" }) 来源: https://stackoverflow.com/questions/4249955/mvc-3-editor-template-with-datetime

asp.net mvc convert \\n new line to html breaks

 ̄綄美尐妖づ 提交于 2019-11-28 21:09:25
I have a textarea in mvc. When data is entered into that and I'm displaying it back to the user, how do I show the line breaks? I display like this: <%= Model.Description%> The following class implements a HtmlHelper that properly encodes the text: public static class HtmlExtensions { public static MvcHtmlString Nl2Br(this HtmlHelper htmlHelper, string text) { if (string.IsNullOrEmpty(text)) return MvcHtmlString.Create(text); else { StringBuilder builder = new StringBuilder(); string[] lines = text.Split('\n'); for (int i = 0; i < lines.Length; i++) { if (i > 0) builder.Append("<br/>\n");

how can mvc return Unauthorized code without redirecting to LogIn view

只谈情不闲聊 提交于 2019-11-28 20:22:59
My MVC web application serves two types of users. First one over standard web browser; Second one over REST returning only JSON data. Additionally, Both require Authentication and authorization; Both scenarios are differentiated based on the route so that I know what content to serve. When users access the application, if they are not logged in, the application should react differently. In the first case it should return the default LogIn page (this is fine). In the second case it should return a 401 Unauthorized code only. I'm used to working with WCF REST service where I could raise an

ASP.NET MVC on IIS falls through to the static file handler

我与影子孤独终老i 提交于 2019-11-28 20:18:16
问题 I have a problem with an ASP.NET MVC site. These are the details: ASP.NET MVC 2 ASP.NET 4 integrated pipeline IIS 7.5 on Windows Web Server 2008 R2 Whenever I make a request for the app I get the "HTTP Error 404.0 - Not Found"-error and the detailed error information shows it is the static file handler that reports the error: Module: IIS Web Core Notification: MapRequestHandler Handler: StaticFile Error Code: 0x80070002 meaning that the request never entered the MVC stack. I should note that

Plus (+) in MVC Argument causes 404 on IIS 7.0

限于喜欢 提交于 2019-11-28 20:14:54
I have an MVC route that is giving me hell on a staging server running IIS. I am running Visual Studio 2010's development server locally. Here is a sample URL that actually works on my dev box: Root/CPUBoards/Full+Size Results Server Error404 - File or directory not found. The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable. Here is the complete behaviour I am seeing. Localhost: Root/CPUBoards/Full Size - Resolves Root/CPUBoards/Full%20Size - Resolves Root/CPUBoards/Full+Size - Resolves Staging Server with IIS 7.0: Root/CPUBoards/Full

The type arguments cannot be inferred from the usage. Try specifying the type arguments explicitly

偶尔善良 提交于 2019-11-28 20:11:16
Could someone please clarify something for me. In my ASP.NET MVC 2 app, I've got a BaseViewModel class which includes the following method: public virtual IDictionary<string, object> GetHtmlAttributes<TModel, TProperty> (Expression<Func<TModel, TProperty>> propertyExpression) { return new Dictionary<string, object>(); } The idea being that each child viewmodel can override this method and provide a suitable set of html attributes, based on some logic, to be rendered in the view: <%: Html.TextBoxFor(model => model.MyProperty, Model.GetHtmlAttributes (model => model.MyProperty)) %> However when

ASP.Net MVC background threads for email creation and sending

感情迁移 提交于 2019-11-28 19:24:00
问题 I'm looking at postmarkapp.com to handle the sending of email from my asp.net mvc 2 application using the .net library that they provide: postmark-dotnet library In their documentation they mention that sending emails w/ attachments can take some time and its better to do this in a background job. For my application I could be sending anywhere from 10 to 500 personalized emails some with attachments in a batch to my users. What is the best way to do this background processing in a non

MVC - Redirect inside the Constructor

China☆狼群 提交于 2019-11-28 19:23:13
I would like to know how am I able to redirect the request inside the controller constructor if I need to do it?. For example: Inside the constructor I need to initialize an object with an dynamic value, in some cases I don't want to do it and in that case I want to redirect to some other place. At the same way the rest of the constructor will not be executed neither the "original following action". How can I do it? Thank you EDIT #1 Initially I used: public override void OnActionExecuting(ActionExecutingContext filterContext) There I could redirect to some other controller/action/url, but

ASP.NET MVC2 + Ninject + NLog (+ shared hosting?) = NullReferenceException

别说谁变了你拦得住时间么 提交于 2019-11-28 19:17:32
问题 I have an MVC2 app that's based on the Tekpub Starter Site, so it uses Ninject for dependency injection, NLog for logging, and a bunch of other libraries in various places. As far as I can tell though, it's these that are causing my problem. Everything works beautifully on my PC using the ASP.NET dev server (Cassini) but when I deploy to the server (it's a cheap shared hosting deal), I get a NullReferenceException that seems to be related to Ninject instantiating the logger. Here's the