asp.net-mvc-2

mvc.net routing: routevalues in maproutes

冷暖自知 提交于 2019-12-04 18:51:38
I need urls like /controller/verb/noun/id and my action methods would be verb+noun. For example I want /home/edit/team/3 to hit the action method public ActionResult editteam(int id){} I have following route in my global.asax file. routes.MapRoute( "test", "{controller}.mvc/{verb}/{noun}/{id}", new { docid = "", action = "{verb}"+"{noun}", id = "" } ); URLs correctly match the route but I don't know where should I construct the action parameter that is name of action method being called. Try: public class VerbNounRouteHandler : IRouteHandler { public IHttpHandler GetHttpHandler(RequestContext

Need a Regex for comma separated number list

北慕城南 提交于 2019-12-04 18:34:13
This should be simple for experienced regex writers, but I don't write them much, so.... I want to do input validation on a text box on a C# MVC form, possibly using javascript or jquery. I want to limit the input to a list of comma-separated integers. The list must start with a number >= 0, followed by a comma and then repeat this pattern. the list may or may not end with a comma: 1,2,444,5, - Pass 1,2,444,5 - Pass ,1,2,444,5, - Fail ,1,2,444,5 - Fail 1,,2,444,5 - Fail 1,,2,444,5,, - Fail I wrote this: ^([0-99],?)+$ and tested it at regexlib.com and it seems to work, but the tester returns 2

MVC Validation using Data Annotations - Model classes or View Model classes?

浪尽此生 提交于 2019-12-04 18:23:55
问题 Is it best practice to put data validation annotations in the Model or View Model? What are the advantages/disadvantages of one approach over the other? Curious to see where everyone is putting their validation, I am currently doing it in the model project. However I have seen a few people say this is not best practice. 回答1: As far as best practices is concerned I would say: in neither of them. Validation should be separate. Frameworks such as FluentValidation allow you to completely separate

Derived RequiredAttribute doesn't work

一世执手 提交于 2019-12-04 18:02:05
I'm trying to implement my own RequiredAttribute, in which I call a custom resource handler: public class LocalizedValidationAttributes { public class LocalizedRequiredAttribute : RequiredAttribute { private String _resourceString = String.Empty; public new String ErrorMessage { get { return _resourceString; } set { _resourceString = GetMessageFromResource(value); } } } private static String GetMessageFromResource(String resourceTag) { return ResourceManager.Current.GetResourceString(resourceTag); } } I call this the following way: [LocalizedValidationAttributes.LocalizedRequiredAttribute

Migrating ASP.NET (MVC 2) on .NET 3.5 over to .NET 4 #gotchas

无人久伴 提交于 2019-12-04 17:51:30
I've currently got a ASP.NET MVC 2 application on .NET 3.5 and I want to migrate it over to the new .NET 4.0 with Visual Studio 2010. Reason being that it's always good to stay on top of these things - plus I really like the new automatic encoding with <%: %> and clean web.config :-) So, does anyone have any experience they could share? Looking for gotchas and the likes. I guess this could also apply to any ASP.NET Forms projects aswell. TIA, Charles Charlino Gotcha #1 - Changes application pool If your ASP.NET project is setup to use IIS and not Cassini, during the upgrade to .NET 4.0 process

Formatting nullable DateTime fields in strong typed View

梦想与她 提交于 2019-12-04 17:47:22
I have a Person class with a BornDate property in my model defined as [DisplayName("Born Date")] public DateTime? BornDate { get; set; } I use this field in my view as <td style="white-space:nowrap"> <%= Html.LabelFor(model => model.BornDate)%> <br /> <%= Html.TextBoxFor(model => model.BornDate, new { id = "bornDate" })%> <%= Html.ValidationMessageFor(model => model.BornDate, "*")%> </td> The problem is that when I am editing a Person instance with the BornDate text box is formatted as dd/MM/yyyy hh.mm.ss while I would like to format it without the time part ("dd/MM/yyyy"). I am not able to

Is there a Perfect/Model ASP.Net Website for Learning Purposes?

瘦欲@ 提交于 2019-12-04 17:46:36
I'm looking for a 'model' website/application written in ASP.Net that illustrates current best-practices of architecture, design, code etc. that could be used as a blueprint for development? I'm working in ASP.Net webforms, but would like to get into MVC so examples from both would be very welcome. Thanks. Nerd Dinner might be worth a look for MVC, it comes with a 185 page pdf walkthough of the code with screenshots. I think it was built as an example for the book ASP.NET MVC 1.0. There's a bit more info on Scott Guthrie's blog You can have a web site that uses ASP.NET MVC and ASp.NET Webforms

Controller ambigous error, upgraded to MVC 2

∥☆過路亽.° 提交于 2019-12-04 17:46:23
I upgraded to MVC 2, updated all my assemblies (did copy to local also). I changed my routes to this: routes.MapRoute( "Admin", "admin/{controller}/{action}/{id}", new { controller = "Admin", action = "index", id = ""}, new[] { "MyNamespace.Web.Controllers.Admin" } // namespace ); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = "" }, // Parameter defaults new[] { "MyNamespace.Web.Controllers" } // namespace ); My controllers look like: /controllers/admin/ProductController.cs /controllers

Is there any way to bind a checkbox list to a model in asp.net mvc

烈酒焚心 提交于 2019-12-04 17:37:52
问题 I am looking here to find a quick and easy way to bind a list of checkbox list items when the postback occurs in the model. Apparently the common way to do it now seems to do it like this form.GetValues("checkboxList")[0].Contains("true"); It seems painfull and not exactly safe. Is there a way to bind a list of checkbox (that are created with or without an helper in the view) or even an array of data for that matters during the UpdateModel(myViewModel, form.ToValueProvider()); phase which

ASP.NET MVC 2 Validate Nested Objects

和自甴很熟 提交于 2019-12-04 17:18:34
According to the spec, complex child properties (aka "nested objects") are validated only if an input is found for one of the nested object's properties. For example, if Person has properties { string Name, Address HomeAddress } and Address has properties { Street, City }, and an action accepts parameter of type Person, then Person.HomeAddress.Street and Person.HomeAddress.City are only validated if the input form had input editors for those nested properties. Is there any way I can force MVC to validate nested objects, even if inputs are not found for their properties? Thanks! I don't think