This is a migrated thread and some comments may be shown as answers.

HTMLAttributes and anonymous types

4 Answers 147 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
jonathan
Top achievements
Rank 1
jonathan asked on 09 Nov 2010, 10:34 PM
Hi all,

Please consider this dropdownlist code:
When using HtmlAttributes what do I do if my anonymous member name is a c# reserved word and a valid HTML attribute? (eg 'class')?  This wont compile (obviously)  how do I set the 'class' htmlattribute? 

I dont want to add the class dynamically based on the ID of the DOM element if I dont have to.......
$("WorkFlowEventTypeId").attr("class","sparseboundcombo);

.HtmlAttributes(new { class"sparsebounddropdown"})          - does not work... how to set class?         

<%= Html.Telerik().DropDownListFor(o => o.WorklflowEventTypeId)
    .DataBinding(binding => binding.Ajax().Select("_WorklflowEventLoading""Workflow"))
.ClientEvents(events => events.OnOpen("rebindCombo"))
.Name("WorkflowEventTypeId")
.HtmlAttributes(new { style "sparsebounddropdown"})                   
%>

4 Answers, 1 is accepted

Sort by
0
NG
Top achievements
Rank 1
answered on 10 Nov 2010, 02:33 AM
try to use "@class" instead of "class"

example:
.HtmlAttributes(new { @class= "sparsebounddropdown"})
0
jonathan
Top achievements
Rank 1
answered on 10 Nov 2010, 03:30 AM
Ooops my bad...
0
jonathan
Top achievements
Rank 1
answered on 10 Nov 2010, 04:19 AM
Sorry my bad.  Not sure how this actually works:


  .HtmlAttributes(new { @class = "adminInput" })                                  
    .DropDownHtmlAttributes( new { @class = "adminInput"})
    .BindTo(ViewData["SpecificationAttributes"] as SelectList)
0
NG
Top achievements
Rank 1
answered on 10 Nov 2010, 07:42 AM
in c#, prefix "@" enable the use of keywords as identifiers, for example @bool, @int, @public and @class.
and "@" itself is not actually a part of identifier, in your case
.HtmlAttributes(new { @class = "adminInput" })
result of @class identifier is actually rendered without "@".

Tags
ComboBox
Asked by
jonathan
Top achievements
Rank 1
Answers by
NG
Top achievements
Rank 1
jonathan
Top achievements
Rank 1
Share this question
or