Asp.Net - AspPageHandler does not fire with button - .net-core

(using .NET Core 3.1)
I have a handler which works, however I can't call it from a <button/>. From an <a/> it works (but this will try to refresh my page and it's not what I want).
//GETS TO HANDLER
<a class="btn btn-info" asp-page-handler="SearchProductionRecords">
<i class="fas fa-file-excel mr-2"></i> Export Excel
</a>
//NEVER GETS TO HANDLER
<span class="input-group-append">
<button type="submit" asp-page-handler="SearchProductionRecords" class="btn btn-info btn-sm"><i class="fas fa-search"></i> </button>
</span>
//HANDLER
public async Task<IActionResult> OnPostSearchProductionRecordsAsync()
{
...
}

A button submit is associated with a form submit. Therefore, put the button inside a form method=post and it should work.
Kind Regards,
Maheshvara

Related

Unable to submit a form when click "input-group-btn"

I am creating a search bar using Bootstrap#input-groups-buttons
<form class="navbar-form navbar-left" action=".">
<div class="input-group">
<input type="text" class="form-control" name="q" placeholder="Search ...">
<span class="input-group-btn">
<button class="btn btn-default" type="button">Go!</button>
</span>
</div><!-- /input-group -->
</form>
When I press Enter, the form could be submitted successfully,
http://127.0.0.1:8000/?q=test
However, when I click the button "Go", nothing happened.
How could I submit the form data when button is click?
Just change the button type as submit.
<button class="btn btn-default" type="submit">Go!</button>.
Check for details: https://www.w3schools.com/tags/att_button_type.asp :)
Suppose your form has the id of myForm
<button type="submit" class="btn btn-default" form="myForm" value="Submit">Go!</button>
I am betting you just need to bind the button to execute your event handler on click events - bootstrap handles the presentation, but you would also want something like jQuery to specify how to handle UI events.
You might want to read: Bootstrap onClick button event

ASP.NET mvc send data (user id) to pop up modal for use in Url.Action that deletes user

I'm new to ASP.NET MVC and I have an app where on the admin page I display a list of users stored in a database, each with their own delete button.
When this delete button is clicked for a specific user, a modal pops up to ask if the admin is sure they want to delete the user. On clicking the confirm button #Url.Action("DeleteUser", "Home" , new { UserID = id }) needs to be called (where id is the selected user's id) but I don't know how to pass the user id from the delete button to the modal in order to delete the relevant user.
Delete Button:
delete button html
<button type="button" class="btn btn-info btn-lg right-float-button"
value=Model.Users[i].ID data-toggle="modal"
data-target="#deleteUser">Delete User</button>
(the Model.Users[i].ID is an int for the current user's id)
Modal: delete user modal
<!-- Modal -->
<div class="modal fade" id="deleteUser" role="alert">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Delete User</h4>
</div>
<div class="modal-body">
<p>Are you sure?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button onclick="location.href='#Url.Action("DeleteUser", "Home" , new { UserID = ?? })'"
type="submit" class="btn btn-default">Delete</button>
</div>
</div>
</div>
</div>
How can I pass Model.Users[i].ID to the modal to be used in the Url.Action where the "??" are?

Change ng-bootstrap buttons activeClass?

In out AngularJs app, we changed the activeClass of buttons (as in toggle groups) to btn-default (from the default btn-primary), so all our CSS expects that.
I notice that ng-bootstrap also defaults to btn-primary but I don't see how (or if) that can be changed.
Is it possible for me to change the activeClass so my CSS is correct with the new components?
ng-bootstrap make use of bootstrap 4. Bootstrap 4 includes six predefined button styles, each serving its own semantic purpose. But it doesn't include a btn-default but with btn-secondary class you achieve the same styling.
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-secondary" [class.active]="model.left">
<input type="checkbox" [(ngModel)]="model.left"> Left (pre-checked)
</label>
<label class="btn btn-secondary" [class.active]="model.middle">
<input type="checkbox" [(ngModel)]="model.middle"> Middle
</label>
<label class="btn btn-secondary" [class.active]="model.right">
<input type="checkbox" [(ngModel)]="model.right"> Right
</label>
</div>
If you still prefer to use the btn-default then you can make a class with that name in your component style and use it.
First of all, which version of angular are you using?
there's quite difference between ng versions
ng-1 angularjs.org - docs
<button ng-class="{'class1 class2 class3' : true}">
it's a button
</button>
ng-2/4 angular.io - docs
<button [ngClass]="{'class1 class2 class3' : true}">
it's a button
</button>

Freemarker request scoped variable for spring.binding

I'm using Freemarker with Spring MVC.
In this code, when I try to bind the local variable "Price" for the nested object in the delete form, it fails with no object available for binding. In JSTL I've solved this nested object problem before by adding the nested price to the request scope with <c:set />.
Is there an equivalent way to do this in Freemarker? or perhaps a recommended alternative approach?
<#list product.prices as price>
<tr>
<td>${price.priceList.name}</td>
<td>${price.priceList.currency}</td>
<td>${DateUtils.formatTime(price.startTime!)}</td>
<td>${DateUtils.formatTime(price.endTime!)}</td>
<td>${price.price}</td>
<td>${price.wasPrice}</td>
<td class="center"><span class="green"><#if price.active><i class="fa fa-check"></i></#if></span></td>
<td>
<a class="btn btn-xs btn-default" href="/admin/products/new/${product.id}/prices/edit/${price.id}"><i class="fa fa-edit"></i> <#spring.messageText "button.edit" "button.edit" /></a>
<form class="inline" action="/admin/products/new/${product.id}/prices/delete/${price.id}" method="post">
<#forms.csrf />
<#forms.hiddenInput path="price.id" />
<button class="btn btn-default btn-xs" type="submit">
<i class="fa fa-trash-o"></i> <#spring.messageText "button.delete" "button.delete" />
</button>
</form>
</td>
</tr>
</#list>

tinymce button trigger click not working

I'm using wordpress and i add some button on editor
i wants to trigger click on that well its triggering click
but not opening light box
for example that button codes looks like
<td style="position: relative">
<a title="Add New Alert" aria-labelledby="content_admin_alert_voice" onClick="return false;" onMouseDown="return false;" class="mceButton mceButtonEnabled mce_admin_alert" href="javascript:;" id="content_admin_alert" role="button" tabindex="-1">
<img alt="Add New Alert" src="http://www.xyz.com/themes/abc/wp-content/themes/abc/admin/js/../img/icon-alert.png" class="mceIcon"><span id="content_admin_alert_voice" style="display: none;" class="mceVoiceLabel mceIconOnly">
Add New Alert
</span>
</a>
</td>
and i'm clicking on #content_admin_alert but actions not happens like we actually click on that button
I haven't played with TinyMCE in a while, but the onClick and onMouseDown events are returning false, which would essentially cancel any click actions.

Resources