asp.net-mvc,dataannotationsRelated issues-Collection of common programming errors
burning_LEGION
c# asp.net-mvc .net-4.0
Here is how I’m doing things now, declaring the string of Roles allowed to access my controller action method:[Role(Roles=”Regular User, Accounting, Administrator”)] public ActionResult ChangeAvatar() {if (User.Identity.IsAuthenticated){var user = _userRepository.FindUserByEmail(User.Identity.Name);var model = new ChangeAvatarModel();model.CurrentAvatarUrl = user.AvatarUrl;return View(model);}return RedirectToAction(“Login”, “Account”); }I don’t want to write up the Roles as a string because I m
teresko
asp.net-mvc asp.net-mvc-2
My model has a property of “output” and my form has a TextBox named “output”, both spelled exactly the same. When I fill out the form and post it, the returning view has unexpected results.Specifically, I receive the posted “output” form variable which is then bound to my Model in the Controller Method, then I change this variable to a different value before I pass the Model back to the view.the posted output property is “one thing” my Model property is set to “another”I have this in my code: &
Laoujin
c# asp.net-mvc action-filter
If some unexpected exception occurs we want to redirect the user to some common error page displaying “Oh noes something went terribly wrong!”However when the exception thrown is OurApplicationException we want to show this in a flash message without redirecting so that the user can correct the problem without having to fill in the entire form again.Can this be achieved with a HandleErrorAttribute? Setting the ExceptionHandled = true; didn’t help here.Or is handling these kinds of errors the job
teresko
c# asp.net-mvc asp.net-web-api asp.net-web-api-routing
I’ve created a new WebAPI MVC project, the API controllers have the path http://localhost:1234/api and they work from this route, but the RegisterRoutes class doesn’t contain a default routing, it contains the following:public static void RegisterRoutes(RouteCollection routes) {routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”);routes.MapRoute(name: “Default”,url: “{controller}/{action}/{id}”,defaults: new { controller = “Home”, action = “Index”, id = UrlParameter.Optional }); }Where’s the routing
Tomalak
jquery asp.net-mvc
I have the the following html elements:<tr> <td> <label for=”casenumber”>Case:</label></td><td><%=Html.TextBox(“casenumber”, “”, new Dictionary<string, object>{{“id”, “casenumberID”}})%></td> </tr> <tr><td><label for=”fogbugzUser”>Users:</label></td><td><%=Html.DropDownList(“UserList”, (SelectList)ViewData[“UserList”], new Dictionary<string, object>{{“id”, “userlistid”}})%></td> <
ioSamurai
c# asp.net-mvc http
What is happening is occasionally at random instead of the HTML being returned to the browser as you would expect, it looks a little something like this:Thread was being aborted.HTTP/1.1 200 OK(the rest of the header)… (like 1/10th of the HTML)That’s it, they are literally getting a bunch of text in the browser window.It doesn’t happen all the time, just randomly. Computers… in my experience always have a reason for everything, ALWAYS. So what’s the heck is going on here?I have searched the
JEMI
jquery asp.net-mvc
I have try to validate an email like below with jQuery in asp.net mvc like below<script type=”text/javascript”>function validateEmail(sEmail) {var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;if (filter.test(sEmail)) {return true;}else {return false;}$(document).ready(function() {$(‘#create’).click(function() {var sEmail = $(‘#UserName’).val();if ($.trim(sEmail).length == 0) {alert(‘Please enter valid email address’);e.prev
O.O
c# asp.net-mvc entity-framework ef-code-first
ControllerFirst I tried this:[HttpPost] public ActionResult Edit(JournalEntry journalentry) {if (ModelState.IsValid){db.Entry(journalentry).State = EntityState.Modified;db.SaveChanges();return RedirectToAction(“Index”, new { id = journalentry.Journal.JournalId });}return View(journalentry); }Error was thrown in SaveChanges():Error Message: “Store update, insert, or delete statement affected anunexpected number of rows (0). Entities may have been modified ordeleted since entities were loaded. Ref
Edi Wang
c# jquery asp.net-mvc json
I got a C# Class:public class JsonAttachmentModel {public Guid AttachmentId { get; set; }public string FileName { get; set; }public string ExtentionName { get; set; } }and the JSON i retrieve is unwellformatted, it is altogether in one string, like:{“success”:false,”message”:”The remote server returned an unexpected response: (413) Request Entity Too Large.”}, {“success”:true,”attachmentId”:”dba60830-46fd-4f51-9cd5-3c20df03988d”,”fileName”:”bz1_20121206113251.PNG”,”extentionName”:”.PNG”}, {“succ
B Z
asp.net-mvc asp.net-mvc-3 razor
ASP.Net MVC 3 RC, RazorExperiencing some unexpected behavior when I try to use a custom message and using client side validation. The problem is it always displays the custom message even though there is no error.So say I have a Client Model where the FirstName is set as Required. If I have the following code the validation message is not displayed until I click on Submit which works as [email protected](model => model.Client.FirstName) @Html.ValidationMessageFor(model => model.Clie
CodeWarrior
entity-framework-4.1 dataannotations
Good day,I am mapping some pre-existing Business Objects to our database using Entity Framework. These object were originally using a home-grown data access method, but we wanted to try out Entity Framework on it now that it is using Code-First. It was my expectation that this would be fairly simple, but now I am having some doubts.I am trying to use only attributes to accomplish this so that I don’t have some of the mapping here, some of it there, and still more of it over there….When I quer
Pretzel
asp.net-mvc validation dataannotations model-binding
Normally, ModelBinding Validation of a class member might be done like this example:public Class someclass {[StringLength(50)]public string SomeValue { get; set; } }SomeValue is limited to 50 characters at a maximum.Is it possible to have the constant (50) changed to something else at run-time, say, during the construction of each instance of that class, so that it is possible to have varying instances with different StringLength limitations?If so, how does one do this?
Jordan Arron
c# dataannotations
Is there away to add and remove DataAnnotations, in particular the [requried], from the code side of things? My problem is that I want to give the user the ability to save an incomplete form in our CRUD applications but at the same time use the power of the DataAnnotations validation. If this is not possible, what is the best way I can go about this?
Simon_Weaver
asp.net-mvc dataannotations
I have certain panels on my page that are hidden under certain circumstances.For instance I might have a ‘billing address’ and ‘shipping address’ and I dont want to validate ‘shipping address’ if a ‘ShippingSameAsBilling’ checkbox is checked.I am trying to use the new DataAnnotations capabilities of ASP.NET MVC 2 (preview 1) to achieve this.I need to prevent validation of the ‘shipping address’ when it is not displayed and need to find the way way to achieve this. I am talking mainly server side
teresko
asp.net-mvc dataannotations
Is it possible to set range (or any other model DataAnnotations attributes) in code and keep all the DataAnnotations behaviour?i.e. I have a decimal model that I want to set its minimum value in code (on page load for example) in a way I could keep using the ValidationMessageFor ?my current “static” model[Required] [DisplayName(“Price”)] [RegularExpression(@”[0-9]+(\.[0-9][0-9]?)?$”, ErrorMessage = “Invalid price format”)] public decimal MinimumPrice { get; set; }Thanks!
Shaggy13spe
vb.net winforms linq-to-sql .net-3.5 dataannotations
Ok, I’m completely at a loss here. I’ve used DataAnnotations attribute DisplayName successfully using MVC model binding, and even with WPF/Silverlight model binding and of course it works just fine, but now I’m on a project that I’m forced to use VB.NET 3.5 WinForms. I have a Linq2Sql model and I created a partial class for one of my classes and included a MetadataType attribute to point to a metadata class. I added a DisplayName attribute to a property in the metadata class. I then bind my
nEEbz
c# asp.net-mvc dataannotations
When I do the following:`[Range(1910, DateTime.Now.Year)] public int Year { get; set; }`I get the following error:An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter typeAny ideas why?
JohnnyO
c# asp.net linq-to-sql linq-to-entities dataannotations
I use Linq to Sql (although this is equally applicable in Entity Framework) for my models, and I’m finding myself creating buddy classes for my models all the time. I find this time consuming and repetitive. Is there an easy way to automatically generate these buddy classes based on the models? Perhaps a visual studio macro?An example of a buddy class that I’d like to create:[MetadataType(typeof(PersonMetadata))] public partial class Person { }public class PersonMetadata {public object Id { g
svick
asp.net-mvc-2 reflection dynamic attributes dataannotations
I have a little bit of a curve ball for you. Maybe just a design issue…maybe even something as simple as me not understanding Data annotation providers.Anyway here we go: I have a class which represents some model data. Let’s say it represents a package/box/carton.It actually represents all of these things so I use the class in several different views. Sometimes I want the attribute of the field Package_Description to be So that it shows up as Box Number : input box here.Now if i want it to
Ronald Wildenberg
asp.net-mvc dataannotations
Apparently it is possible to dynamically attach DataAnnotation attributes to object properties at runtime and as such achieve dynamic validation.Can someone provide code sample on this?
Web site is in building