Hi Guys, I've used the partial view code snippet for a login but would like to add classes to the form and the input elements (Bootstrap site, so for example would like to add .form-control class to the inputs) but can't find where to do this. In the macro the razor code is: @Html.TextBoxFor(m => loginModel.Username) and can't find anything for login model or login controller anywhere. Thanks for any help! cheers Steve
Hi Gary, Thanks but in this case I'm using the code generated when you create a Partial View in the back office and select 'Use a Code Snippet'. One of the options is 'Login' and the main block of code rendered is:
Hi Gary, Yes, no problem finding the file itself but would like to know where to add the class names to the input elements. Eg How do I add 'form-control' class to the username textbox? And where is the form tag generated? Thanks, Steve
How to add classes to code snippet elements?
Hi Guys,
I've used the partial view code snippet for a login but would like to add classes to the form and the input elements (Bootstrap site, so for example would like to add .form-control class to the inputs) but can't find where to do this.
In the macro the razor code is:
@Html.TextBoxFor(m => loginModel.Username)
and can't find anything for login model or login controller anywhere.Thanks for any help!
cheers
Steve
Hi Steve
Here is a snippet from my code on bootstrap form.
Without the rest of your code can't say exactly how to to it, but you need the following-
Hope you can see what you need from there.
Regards
Gary
Hi Gary,
Thanks but in this case I'm using the code generated when you create a Partial View in the back office and select 'Use a Code Snippet'. One of the options is 'Login' and the main block of code rendered is:
I'd like to add the bootstrap classes to the form and input elements but can't find where to do that.
Thanks, Steve
Hi Steve
That file can be found at Umbraco/PartialViewMacros/Templates/Login.cshtml.
You can edit it there or copy it into your own partial.
Cheers
Gary
Hi Gary,
Yes, no problem finding the file itself but would like to know where to add the class names to the input elements. Eg How do I add 'form-control' class to the username textbox? And where is the form tag generated?
Thanks, Steve
Hi Steve
You can pass an anonymous object containing the attributes you want output to the html helper.
In your case you could do:
'class' needs an '@' before it as it is a reserved c# keyword.
Lewis
Lewis - that's it! Thanks!
Hi Steve
Apologies - got the wrong end of the stick there.
OK, that's all in Bootstrap, all css. (There are a couple of bootstrap form generators on the web, I have used them then just add in your fields)
As long as you have the id, name etc as the fields you require, the form will be completed.
Will say this did confuse me at first, but the @Html.TextBoxFor() only generates css (HTML5) so it can be replaced.
Hope that makes sense
G
is working on a reply...