Image on ActionLink with Twitter Bootstrap - css

I have a button at the moment, rendered in my MVC application as:
#Html.ActionLink("Delete", "DeleteTransfer", "Transaction", new { transferId = (Model.Id) }, new { #class = "btn btn-danger", #onclick = "return confirm('Are you sure you want to delete this Transfer?')" })
I want to use the Twitter Bootstrap classes to add an icon. However, for that the code would look like this:
<button class="btn btn-danger"><i class="icon-white icon-trash"></i> Delete</button>
How can I apply this in my ActionLink? It has an Image (i) embedded in the button.

Try:
<a class="btn btn-danger"
href="#Url.Action("DeleteTransfer", "Transaction", new { transferId = (Model.Id) })"
onclick = "return confirm('Are you sure you want to delete this Transfer?');"
>
<i class="icon-white icon-trash">Delete</i>
</a>
According your routes, it's possible you need:
#Url.Action("DeleteTransfer", "Transaction", new { transferId = (Model.Id) }, null)

According to the bootstrap documentation (http://getbootstrap.com/components/#glyphicons-examples) glyphicons might be the way to go. Here is an example of putting an icon on a button:
<button type="button" class="btn btn-default btn-lg">
<span class="glyphicon glyphicon-star"></span> Star
</button>
Since ActionLink() is an htmlHelper extension that returns an "a" element, i.e., <a>...</a>, I believe the extension needs to be overridden.
I tried the following, but it resulted in the glyphicon being above the "a" element:
<span class="glyphicon glyphicon-star"></span>#Html.ActionLink("Delete", "DeleteTransfer")
I also tried putting the ActionLink() inside the <span></span> with the same results. I tried using css with text-wrap: none; and white-space: nowrap; but that didn't work either.
So I believe the answer is the extension needs to be overridden to accept another parameter for the glyphicon. Unless, someone can show a trick to make it stop wrapping.

Related

Angular: "btn" class disappear after toggled the button

I have an issue with the class changing button. I use the [ngClass] directive to change the button style ( Bootstrap classes). But when I click the button, the "btn" class disappears from the code, so instead get 'btn-success btn', I get only 'btn-success'. The button also takes a part in showing and hiding a paragraph with random text.
This is TS code:
<button type="button"
(click)="onClick($event)"
[ngClass]="{'btn-success btn': showPass, 'btn-danger btn': !showPass }">{{status}}
</button>
<p [hidden]="showPass" >Secret password</p>```
and this is HTML:
onClick(event: Event) {
this.showPass=!this.showPass;
this.status = this.showPass ? "Show me!" : "Hide me!"
console.log(this.showPass)
If the btn class is always going to be there, you can just do this instead:
<button type="button"
(click)="onClick($event)"
class="btn"
[ngClass]="{'btn-success': showPass, 'btn-danger': !showPass }">{{status}}
</button>

Redirecting by buttonclick in asp.net

I have a very simple issue in my asp.net core mvc project.
I have a button in one of my views, and when this button is clicked, I want to redirect to a specific controller, and a action in this controller.
Currently it looks like this:
<button class="dropbtn" class="glyphicon glyphicon-user"> something</button>
I've been looking around for methods of doing this, and one of the solutions I found, was the #Html.ActionLink("pik", "Index", "Home").
So I tried:
<button onclick="#Html.ActionLink("pik", "Index", "Home")" class="dropbtn" class="glyphicon glyphicon-user"> Log in </button>
However this is just displayed as raw html. Does'nt work.
Then, here I found this:
<button nclick="location.href='<%: Url.Action("Action", "Controller") %>'" class="dropbtn" class="glyphicon glyphicon-user"> Log in
However, my IDE just gives a bunch of unexpected token in this line. I don't undestand it either.
I then found this:
#using (Html.BeginForm("Index", "Home", FormMethod.Post)){
<button type="submit" class="btn btn-default" class="dropbtn" class="glyphicon glyphicon-user">Submit</button>
}
This works in terms of the button, but for some reason, when I wrap the button in a form, my styling gets messed up.
I would rather not use javascript for redirecting.
So how can I redirect to a controller action with a button?
#Html.ActionLink() creates an html link with an <a> tag. If you are using Bootstrap (highly recommended) you can use this.
Click Me
or if you want to use helpers, like this
#Html.ActionLink("pik", "Index", "Home", new { #class = "glyphicon glyphicon-user" })
This is the cleanest way I know of to create button with a link.
You can also check this out.

How do I get the xpath, or other locators?

I needed help to get the best possible element locator can I use for a button with the following code;
<button onclick="btnProcess($(this), 'Adding...','fa-refresh fa-spin',0);callServer('/DejavuMobile/action/UserGroupModel_AddItem/Users/Add?hfUsername=8_44&ic=44&hfService=', function(response){ btnProcess($(this), 'Add new item','fa-plus',1);loadContent($('#UserAddUI') ,response); });" class="btn btn-xs btn-labeled btn-info" type="button" style="padding-right:12px;padding-left:12px;margin-left:15px;margin-bottom:15px;"><span class="btn-label"><i class="fa fa-plus"></i></span>Add new Group</button>
The most readable one:
//button[text()='Add new Group']
It's possible to create path using class or any other attribute, but by text in this case is the most clear and easy way.

Bootstrap dropdown: change dropdown icon when it's active?

I have the following setup:
<div data-ng-repeat="item in navigationBar.navObject.items" class="btn-group">
<button data-ng-class="{current: $last}" class="btn btn-default btn-xs" type="button" data-ng-click="navigationBar.goToState(item)"> {{item.name}}</button>
<button data-ng-hide="item.isTerminal" data-toggle="dropdown" class="btn btn-default btn-xs dropdown-toggle" type="button">
<span class="fa fa-fw fa-caret-right"></span>
</button>
<ul class="dropdown-menu">
<li data-ng-repeat="subItem in item.subItems"><a data-ng-click="subItem.item.goToState()">{{subItem.name}}</a></li>
</ul>
</div>
And I would like the icon in the dropdown to change from fa-caret-right to fa-caret-down when the dropdown list is visible. Is there any way to do this strictly with CSS?
You won't be able to change the attributes of HTML elements using CSS, you'll probably want to use jQuery instead.
Bootstrap has some nifty JavaScript going on, where you can execute your own scripts when boostrap elements inside your website is used.
Initialize dropdown using this inside jQuery.
$('.dropdown-toggle').dropdown();
When it's called you can hook different actions to it using the handles specified on the bootstrap docs.
on('show.bs.dropdown', function(){}); is just a fancy word for saying "on dropdown"
$('.dropdown-toggle').on('show.bs.dropdown', function () {
// All actions to fire after the dropdown is shown go here.
$('.fa .fa-fw').addClass('fa-caret-right');
$('.fa .fa-fw').removeClass('fa-caret-down');
})
I know this is an old post, but I was looking for this solution and have one that works for me. You can target and change the pseudo element inside that span. When you click the button, doesn't the button add an open class? So, then the css would look like:
btn.open .fa-caret-right:before { content: "\e114"; }
Use the .open added to the button class.
The \e114 being the character of the down arrow.

Creating a split-button-dropdown in asp.net MVC with Twitter Bootstrap

I am trying to create a split button dropdown using Bootstrap and ASP.NET MVC 5, but I cannot seem to render the correct markup. This is what I have so far...
<div class="btn-group">
#Html.ActionLink("Details", "Details", new { id = item.ClientTypeID }, new { #class = "btn btn-sm btn-primary" })
<a class="btn btn-sm dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>#Html.ActionLink("Edit", "Edit", new { id = item.ClientTypeID })</li>
<li>#Html.ActionLink("Delete", "Delete", new { id = item.ClientTypeID })</li>
</ul>
</div>
I have no doubt that this is my own fault, but can anybody please point out what I should actually have in my template. Instead of the required drop down, I am seeing the initial "Details" button, and I am seeing the drop down caret, but clicking on the caret does not show the additional items.
In case it makes a difference, I am using the default templates from VS2013 along with the Cosmo theme from Bootswatch. This is also being rendered in a table cell.
Thanks.
Make sure you have registered jQuery before bootstrap.min.js.
Debug the error using Developer Tools available in all modern browsers.
Chrome use Ctrl+J, IE use F12, FireFox use Shift+F2
Happy Coding..

Resources