1

I am pretty new to MVC and just learning by example, so far I was able to do

@Html.RadioButton("settings", "UpdateEmail")

But is there a way like extra params maybe so I can also set some outline:none and alignment attributes for it?

In Google I found this example but he is not passing CSS either: http://www.tutorialsteacher.com/mvc/htmlhelper-radiobutton-radiobuttonfor

2 Answers 2

3

Each HTMLHelper in Razor has the htmlProperty parameter, which accept an object and will print the properties of this object inside the html.

So, if you want to set a CSS class, you can do this:

@Html.RadioButton("settings", "UpdateEmail", new {@class = "myCssClass"})

Which will become into this:

<input type="radio" name="settings" value="UpdateEmail" class="myCssClass">

And you can set any property in this way:

@Html.RadioButton("settings", "UpdateEmail", new {@class = "myCssClass", style="width: 100px", disabled="disabled"})

Note: The @ before the property named class is required because class is a reserved word, so using @class allows you tu use this word.

Sign up to request clarification or add additional context in comments.

Comments

2

I believe you can do it like this:

@Html.RadioButton("settings", "UpdateEmail", new { @class="inputclass" })

or

@Html.RadioButton("settings", "UpdateEmail", new { style="outline: none;" })

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.