custom-attributes

Uppercase attribute that converts the input to uppercase

时光总嘲笑我的痴心妄想 提交于 2019-11-29 06:57:13
I am working in MVC4 and want to define a model using an Uppercase attribute. The idea would be that the presence of the Uppercase attribute would cause the model value to be converted to uppercase when it arrived at the server. At the moment I have the following code within the model: [Required] [Display(Name="Account Code")] [StringValidation(RegExValidation.AccountCode, Uppercase=true)] public string Account { get { return _account; } set { if (value != null) _account = value.ToUpper(); } } But what I would really like is this: [Required] [Display(Name="Account Code")] [StringValidation

is it possible to set custom attribute by jQuery attr() function using JS variables

回眸只為那壹抹淺笑 提交于 2019-11-29 06:39:20
问题 I'm using jquery 1.5 and html4 standard. I'm trying to set custom attribute which i get by javascript variable, but it is not setting up.code sample: var attname="list1"; // this is changed on every call of the function where it is defined. var attvalue="b,c,d"; // this also changed. jQuery('#div1').attr({attname:attvalue}); but it treat attname as string itself rather variable. there are other option like using data(),prop() but they are supported in HTML5 and jquery 1.6 that is not possible

Adding custom attributes to an asp:CheckBox control

China☆狼群 提交于 2019-11-29 06:08:05
I am trying to add a custom data-required attribute to an asp Checkbox control, it works fine for all other controls I've used it on, but on checkboxs it renders the checkbox inside a span that has the custom attribute on. I've tried adding the attribute in the markup and tried adding it to the control in the code behind. Any ideas? use InputAttributes Here is the code I have used: cb.InputAttributes.Add("data-group", "chkbox"); Then you can use JQuery to target all check-boxes. $("*[data-group='chkbox']").prop("checked", true); 来源: https://stackoverflow.com/questions/9939287/adding-custom

Finding custom attributes on view model properties when model binding

。_饼干妹妹 提交于 2019-11-29 05:46:51
I've found a lot of information on implementing a custom model binder for validation purposes but I haven't seen much about what I'm attempting to do. I want to be able to manipulate the values that the model binder is going to set based on attributes on the property in the view model. For instance: public class FooViewModel : ViewModel { [AddBar] public string Name { get; set; } } AddBar is just public class AddBarAttribute : System.Attribute { } I've not been able to find a clean way to find the attributes on a view model property in the custom model binder's BindModel method. This works but

ASP.NET MVC: Ignore custom attribute in a base controller class

时光毁灭记忆、已成空白 提交于 2019-11-29 04:59:23
I have a number of Controllers in my project that all inherit from a controller I've named BaseController. I wrote a custom attribute that I applied to the entire BaseController class, so that each time an action runs in any of my controllers, that attribute will run first. The problem is that I have a couple of controller actions that I'd like to ignore that attribute, but I don't know how to do it. Can anyone help? I'm using MVC 1. Thanks. I had a similar need for something like this and found that by creating an authorization filter (implementing/deriving from FilterAttribute,

jQuery and data-attributes to handle all ajax calls?

眉间皱痕 提交于 2019-11-29 04:32:55
I'm thinking of a way to reduce the amount of javascript code by enabling ajax on links from attributes. Example: <a href="/Default/Link.html" data-endpoint="/Ajax/Link.html" rel="targetId" async="true">Click me!</a> async="true" will disable default behaviour of the link ( href ), and do a ajax call using the data-endpoint value and insert it to the element id defined in rel . I'm no JS expert, so I'd appreciate any thoughts or pitfalls using this approach. Options like cache: true etc would be cool to be able to pass in as well, but not really needed as I'd like to do this to get partial

Magento - Show Custom Attributes in Grouped Product table

醉酒当歌 提交于 2019-11-29 04:11:22
问题 I need to find a way to show the value of a custom attribute in place of the "Product Name" shown in the image below. (source: magentocommerce.com) I'm working with /app/design/frontend/default/defaultx/template/catalog/product/view/type/grouped.php The code below doesn't work(the custom attribute is yearmade): <?php if (count($_associatedProducts)): ?> <?php foreach ($_associatedProducts as $_item): ?> <tr> <td><?php echo $this->htmlEscape($_item->getYearmade()) ?></td> Any help would be

Are Custom Attributes OK in XHTML

非 Y 不嫁゛ 提交于 2019-11-29 03:23:52
I understand that according to the HTML specification, it's invalid to add custom attributes to elements. Is this also invalid with XHTML? I thought XHTML was part of the XML family, and as such was extensible. Being extensible, isn't it ok to use custom attributes? Dave custom attributes won't be considered valid by the standard W3C validators. You can define your own document type definition (DTD) though. See http://www.alistapart.com/articles/customdtd/ for more information about that. With the standard document type definition, you can't introduce your own custom attributes. But, starting

jquery: get value of custom attribute

↘锁芯ラ 提交于 2019-11-29 00:53:56
html5 supports the placeholder attribute on input[type=text] elements, but I need to handle non-compliant browsers. I know there are a thousand plugins out there for placeholder but I'd like to create the 1001st. I am able to get a handle on the input[placeholder] element but trying to get the value of the placeholder attribute is returning undefined - $("input[placeholder]").attr("placeholder") . I'm using jquery 1.6.2. Here is the jsfiddle . I modified the code to work in a browser that is html5 compatible just for testing purposes. html <input type="text" name="email" size="10" placeholder=

Using action parameters in custom Authorization Attribute in ASP.NET MVC3

谁都会走 提交于 2019-11-28 18:45:49
I have a controller which should only request authorization when loaded with specific parameters. Like when the parameter ID is 8 for example. I came up with using a custom validation attribute like this: public class MyAuthorizeAttribute : AuthorizeAttribute { protected override bool AuthorizeCore(HttpContextBase httpContext) { if (/* Action's inputparameter ID = 8 */) { return base.AuthorizeCore(httpContext); } return true; } } My action looks like this (not that it is interesting) [MyAuthorize] public ActionResult Protected(int id) { /* custom logic for setting the viewmodel from the id