MVC2 Not Replacing Underscores With Dashes In HtmlAttributes?

Nov 9, 2010

I've heard from a couple of different sources that when using HTML helpers in ASP.NET MVC2, one can create custom attributes with dashes in them (e.g. <a data-rowId="5">) by using an underscore in place of the dash, and when the HTML is written to the page the underscores will be replaced by dashes.

So, something like this:

<%= HtmlActionLink(Model.Name, "MyView", null, new {data_rowId = Model.id}) %>

should render as

<a data-rowId="0" href="myURL">Row Name</a>

But... it's not. I think that maybe this feature is only enabled in the MVC3 Beta preview (as it's mentioned in the MVC3 preview release notes), but this thread is about the same thing, and it's regarding MVC2.

I know I can use the other solution presented in that thread, but I'd rather not have to resort to using the dictionary if a more elegant solution exists.

View 2 Replies


Similar Messages:

Skip Dashes While Grabbing Number?

Mar 25, 2011

I have a number of 0-12345-67890 and I want to capture 0123456789 in a named capture group. I got this far:

@"(?<upc>d-d{5}-d{5})"

Which captures the string as-is. How do you skip the dashes while grabbing the number as a single named group? BTW, this is ASP.NET Regex.

View 2 Replies

MVC :: Converting Underscores In Anonymous Objects To Hyphens?

Dec 2, 2010

anonymous attributes with underscores are supposed to render as hyphens to allow unobtrusive ajax attributes.

It works fine for this:

@Html.TextBox("Name","Value", new {data_unobtrusive_attr="attrValue"})

gets correctly rendered as this:

<input type="text" name="Name" value="Value" data-unobtrusive-attr="attrValue" />

However, it doesn't work for the Ajax.BeginForm helper (kinda the most important place for that to work!) -- the underscores just stay as underscores.

View 5 Replies

AJAX :: MaskedEditExtender Phone Dashes In Mask

Feb 11, 2010

I just started using the mask control. I have it working exactly the way I want with date but can't get the same behavior with Phone.

<AjaxControlToolkit:MaskedEditExtender
ID="mskTbTicketOpenedDate"
runat="server"
TargetControlID="tbTicketOpenedDate"
Mask="99/99/9999"
MessageValidatorTip="true"
OnFocusCssClass="MaskedEditFocus"
OnInvalidCssClass="MaskedEditError"
MaskType="Date"
ErrorTooltipEnabled="True" />

Date Mask Validator:

<asp:RequiredFieldValidator
ID="rfValTbTicketOpenedDate"
runat="server"
ControlToValidate="tbTicketOpenedDate"
Display="Dynamic"
ErrorMessage="required!<br />" />
<AjaxControlToolkit:MaskedEditValidator
ID="mskValTbTicketOpenedDateInvalid"
runat="server"
ControlExtender="mskTbTicketOpenedDate"
ControlToValidate="tbTicketOpenedDate"
IsValidEmpty="false"
InvalidValueMessage="Date is invalid<br />"
Display="Dynamic" />

Breaking out the required field validation helped me get the date textbox to behave the way I need. Just positioning validation messages and such. Behavior I like here is that TextBox has no mask to start (focus off of textbox). When you put the cursor in the textbox or the textbox gets focus then the mask shows up: __/__/____. As you type the underscore placeholders dissapear but the '/' chars stay in place.

And finally, this is key, when you have a correct date and take the focus away from the text box the dashes stay in place. I just realized that is because the date mask seems to fill in the blank spaces with the current date. I cannot get this behavior with a phone. Granted there is no phone mask type. Here is the phone code:

<AjaxControlToolkit:MaskedEditExtender
ID="mskTbPhone"
runat="server"
TargetControlID="tbPhone"
Mask="999-999-9999"
ClearMaskOnLostFocus="true"
MessageValidatorTip="true"
OnFocusCssClass="MaskedEditFocus"
OnInvalidCssClass="MaskedEditError"
MaskType="None"
ErrorTooltipEnabled="True" />

I have tried MaskType set to number but it doesn't change the behavior. Right now the dashes dissapear when I take the focus off of the phone textbox. One thing I noticed with date is that if it is incomplete when it loses focus it fills in the rest with the current date values. Since there is no Phone mask type that behavior is not built in. Does anyone know how to set a default behavior so if you type in 55 in would automatically finish? 555-55-5555 And when you take the focus off it would keep the dashes. But if the textbox is empty I want with no focus the mask should dissapear completely.

View 3 Replies

MVC :: Trying To Use ActionLink With RouteValues And HtmlAttributes?

Nov 28, 2010

I am trying to use ActionLink with routeValues & htmlAttributes

[Code]....

View 3 Replies

MVC :: Don't Understand HtmlAttributes Parameters?

Jan 27, 2010

Don't understand htmlAttributes parameters? try this:

[Code]....

[Code]....

How to correct?

[Code]....

View 11 Replies

Web Forms :: ValidationExpression To Just Accept A-Z, 0-9 / Hyphens / Underscores / Spaces?

May 11, 2010

Using a RegularExpressionValidator, I want my textbox to accept a max of 20 chars, and only English characters A-Z (upper and lowercase), 0-9, hyphens (-), underscores (_), and spaces. That's it.

Now that I think about it, since this text will be used by a proprietary software to create a file of the same name, and will also be included in the querystring when the page is redirected (so that I can find the file so the user can download it), I'm not sure if I should keep it safe and not accept spaces.

View 4 Replies

WCF / ASMX :: Svcutil Generates Underscores In Enum With Type Int?

Feb 8, 2011

i am generating a wcf data contract from a schema, using svcutil /d: option, however the enum of type xsd:int in schema is generating all the values as ints, with underscores, obviously to make valid code. How can i get the actual value of 1000

E.g Enum Impact with values 1000,2000,3000 generates code

public enum Impact : int
{
[System.Runtime.Serialization.EnumMemberAttribute(Value = "1000")]
_1000 = 1,
[System.Runtime.Serialization.EnumMemberAttribute(Value = "2000")]
_2000 = 2,
[System.Runtime.Serialization.EnumMemberAttribute(Value = "3000")]
_3000 = 3
}

View 2 Replies

MVC :: Use TextBoxFor With A DateTime Field (in Particular - Add HtmlAttributes)?

Apr 9, 2010

I'm having a problem understanding how to use TextBoxFor with a DateTime field (in particular how to add htmlAttributes). MVC has helpfully scaffolded the following for me:

[Code]....

I now want to add an htmlAttribute to this, to make the rendered <input> element read-only, for example:
new {@readonly="true"} The problem I have, is that the MSDN documentation for TextBoxFor (see [URL] says only allows two arguments are allowed, the LINQ expression, and a dictionary or object containing the htmlAttributes. So I have two questions:

1. What is the role of "String.Format("{0:g}", Model.LastPolled)" in the scaffolded version? This obviously works, but doesn't seem to be an htmlAttribute.

2. How should I modify the scaffolded version so that the readonly attribute will be used?

View 8 Replies

Web Forms :: >>>Remove Dashes, Hashes, Spaces Populating Dropdown?

Aug 8, 2010

I have been searching the forum for how to populate a dropdown without "spaces" or "-" but I can not find exactly what I am looking for.Actually the data input by the user contains specaial character and using datasource the dropdown is being populated with the original data but every user has different style to insert data so I want to populate dropdown(within forview) without spaces or dashes, hashes. By making this change I may be able to populate dropdown in an asc or desc order.I know it can be handle from database but I want to do it with some coding technique in vb.net or asp.net.

View 11 Replies

MVC :: RouteValueDictionary For HtmlAttributes In HTML Helpers - Finding Alternative

Jun 2, 2010

MVC 1.0 source has code like

[Code]....

Was RouteValueDictionary intended for use with htmlAttributes? Is there an alternative? The only 'feature' RouteValueDictionary looks like its got is it has a constructor which accepts an object.

What should I be using in custom helpers?

View 2 Replies

Web Forms :: Replacing SSN In Code-behind?

Jan 26, 2011

I am collecting information and sending an email confirmation on form-submit. I want to find any instances of SSNs in the body of the email and replace the beginning digits with "X". I'm trying to use a regex to find/replace:

emailBodyConf = Regex.Replace(emailBodyConf,
"^d{3}-d{2}-d{4}$",
"XXX-XX-XXXX"
)

This code above isn't replacing anything, but what I really want to do is replace the first five digits and leave the last four.

View 6 Replies

Replacing A Website That Uses Frames?

Mar 16, 2011

My website currently uses frames. My index.html homepage looks something like this:

[Code]....

Well, apparently frames are way outdated, "element frameset is not supported" in XHTML Transitional 1.0 and "newer constructs are recommended." So, what do I do instead?

View 2 Replies

MVC :: Replacing TextBox With Combobox?

Feb 21, 2011

I am still learning and improving myself in ASP.NET MVC.I have partial view with following lines to get a input from users for Category field. It is working absolutely fine.

<%: Html.LabelFor(model => model.Category) %>
<%: Html.TextBoxFor(model => model.Category) %>

I want to replace this with set of values in Combobox and allow user to select any one of them.Could anyone please tell me how could I achieve it.

View 6 Replies

Contentplaceholder For Replacing Attributes?

Nov 10, 2010

The code below works but confuses Visual Studio. Are there alternative/better ways to accomplish this?

<body <asp:contentplaceholder id="BodyAttribute" runat="server"/>>

View 3 Replies

Replacing A Control At Runtime?

Oct 14, 2010

I have an existing .NET 1.1 dll that I do not have the source code for. It contains the code-behind for a asp.net page containing various form controls including a third party text editor that I no longer want to use. I want to replace the text editor with a simple asp:Textbox but the existing textbox is baked into the old assembly. How can I override / extend the existing page to use a textbox instead of the old text editor control?

View 1 Replies

Replacing UpdatePanel With Jquery?

Nov 17, 2010

does anyone know if its possible to replace the updatepanel in asp.net ajax toolkit with some kind of jquery?

Basically we use the update panel so that when we do postbacks that the screen doesn't actually do a full refresh .. just the values ..

I am using jquery for a lot of other stuff and would love to know if there is some way to do this or even if a jquery plugin exists that lets you do it.

I am a bit unsure but would this mean i have to rename all my methods to static and decorate with the webmethod attribute?

If this is the case, it maybe a lot of work :-)

And of course how would Page_Load execute if it was a static webmethod?

View 1 Replies

Replacing Last Comma In String With Different Character

Oct 23, 2010

i have a string, and i want to replace the last comma with something else. For instance this is my string;

"Monday, December 6, 9:00 PM"

How do i replace that last comma so it can look like this;

"Monday, December 6 2010 9:00 PM"

View 4 Replies

Replacing The Obsolete System.Xml.XmlDataDocument?

Sep 20, 2010

I have a System.Web.UI.WebControls.Xml control (Xml1) in a webforms app that I have upgraded from .NET 2.0 to .NET 4.0

I am getting two warnings from the code-behind page that I'd like to do something about.

[code]....

'Public Property Document As System.Xml.XmlDocument' is obsolete: 'The recommended alternative is the XPathNavigator property. Create a System.Xml.XPath.XPathDocument and call CreateNavigator() to create an XPathNavigator.

View 3 Replies

Reading & Replacing Spanish Characters

Jul 16, 2010

Using vb.net/asp.net

I am reading names from a file, some of them have special spanish characters like this: ñ

My end goal is to replace the special characters, however when I read the names into a string and then put a breakpoint and run my program in debug to see what I'm reading in my watch window shows a square in place of the special characters as if it's having problems reading the special characters.

EX:Muñoz from the file

is displayed

Mu�oz in my vb.net string

what I need to do so that my vb.net code and correctly read the special characters?

View 1 Replies

Replacing The IE Web Controls Multipage Control?

Feb 14, 2011

I have an intranet web project that is currently using the IEWC tabstrip and multipage controls.

Since these are very out of date, and cause lots of issues when trying to support multiple browsers, I am trying to find a good way to replace these controls, preferably without and drastic changes to the site's design or usability. One method I am considering is using jquery UI tabs, which looks like it might work in a similar fashion.

How can I replace these outdated controls?

Current snippet:

<iewc:tabstrip id="ts1" style="position:relative; float:left;" runat="server" TargetID="mpVert">
<iewc:Tab HoverImageUrl="images/selected_tab1.gif" SelectedImageUrl="images/selected_tab1.gif"
DefaultImageUrl="images/unselected_tab1.gif"></iewc:Tab>
<iewc:Tab HoverImageUrl="images/selected_tab2.gif" SelectedImageUrl="images/selected_tab2.gif"
DefaultImageUrl="images/unselected_tab2.gif"></iewc:Tab>
</iewc:tabstrip>
<iewc:multipage id="mpVert" runat="server" BorderWidth="1px" BorderStyle="Outset"
style="position:relative; float:left; width:99.9%; min-height:200px;">
<iewc:PageView>
<SampleControl:MyControl runat="server" id="sampleControl" name="JustAnExample" />
</iewc:PageView>
<iewc:PageView>
<div>More stuff in here for tab 2</div>
</iewc:PageView>
</iewc:multipage>

One of the issues I am running into is that the site was originally designed with the expectation that the controls on every tab would be included in the page for every request. This could be changed, but as this is a side project, I'm hoping to find a way to work around this.

View 3 Replies

Configuration :: Replacing System.web/sitemap With WDP?

Mar 18, 2011

Is it possible to replace the sitemap section of web.config using the replacement functionality of Web Deployment Projects? I have tried doing this in every configuration I can think of and I get a WDP00002 missing section error every time.Web.config file section replacement command: system.web/sitemap=sitemap.configBoth .config files are in the root of the project and no matter how I set up the sitemap.config file I still get this error.

View 1 Replies

Replacing A Characters Instead Of Space Between Words?

Dec 16, 2010

How I can Replace charachter '+' Instead of Space between this words or sentencefor Example :

Before = I like ASP.NET
After = I+like+ASP.NET

View 2 Replies

Replacing .NET Ajax Controls With JQuery?

Aug 17, 2010

I have a solution that uses Accordian and tab controls, amongst others.Is it worth swapping these out and use the jQuery controls instead?

What are the benefits? Is it best practice to load one tab at a time with data?

View 2 Replies

Replacing Spanish Characters With The English Equivalent

Jul 22, 2010

Using vb.net 2005/asp.net I thought I had the issue solved: I have some strings with spanish characters such as "ñ" and I need to replace characters with their non-spanish equivalent, ex: the example I just mentioned would be changed to "n".

[Code]....

when I put a breakpoint I see that usually my code replaces the characters the way that I want and all is good but some replacements are not working well and looking at my breakpoint it appears that there are non-readable characters that are included with the spanish characters and it seems that I need to do some kind of normalization on the string but not sure what to do. I have a text "caroliné" that i processing and in the code above it appears to replace the last char with an "e" but when I return the value from the function I am able to see some non readable characters (appearing on my watchlist as a small square) and the resulting string is actually "carolina" which is confusing.

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved