How to call Controller Action on standart html event in Asp.Net MVC?
Date : March 29 2020, 07:55 AM
around this issue It's pretty simple. You can either use the built in Ajax.BeginForm in MVC land, or you can use jQuery to send the request. I'll show you the jQuery example (simply because jQuery makes ajax stupidly easy and it's easy to write): $('#myDropDownIdAttribute').change(function()
{
$.ajax({
url: 'Some/ActionName', // SomeController, ActionName
data: { selectedValue: $(this).val() },
success: function()
{
// Success Callback
}
});
});
public ActionResult ActionName(string selectedValue)
{
// Do Stuff
}
|
Why does Action event on a button does not call the controller function
Date : March 29 2020, 07:55 AM
I hope this helps you . You'd do it like this. Please note that there were a few things wrong with your code: 1) You handlebars code with your button in it was not wrapped in a handlebars script tag 2) You're 'modules' template was in the application template 3) You did not include valid links to the necessary libraries 4) There was not rootElement specified for the Application 5) You tried to access ModulesController in the ApplicationRoute. I inserted a redirect to 'modules' 6) You tried to access module in your {{#each}} loop, but that does not exists in your model. What you want is content. <script type="text/x-handlebars" data-template-name="application">
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="modules">
<ul>
{{#each content}}
<li>{{this}}</li>
{{/each}}
<button {{action 'modules'}} > press </button>
</ul>
</script>
var Test1 = Ember.Application.create({
rootElement: 'body',
ready: function() {
console.log("App ready1");
}
});
Test1.IndexRoute = Ember.Route.extend({
redirect: function() {
this.transitionTo('modules');
}
});
Test1.Router.map( function() {
this.route('modules');
});
Test1.ModulesController = Ember.Controller.extend({
actions: {
modules: function() {
console.log('clicked the button');
/* this.transitionToRoute('modules');*/
}
}
});
Test1.ModulesRoute = Ember.Route.extend({
model: function() {
return ['item1', 'item2'];
}
});
|
How to add an event listener to an action from external controller?
Date : March 29 2020, 07:55 AM
it helps some times I have found one possible way in the meantime to flush the controllers to create the RouteCollection and retrieve it via binding name. You will receive a Route instance and can use there the normal middleware listener methods like before, after and so on. $app->flush();
$route = $app['routes']->get('control.start');
$route->before(function(Symfony\Component\HttpFoundation\Request $request) use ($app) {
throw new RuntimeException('You should see me.');
});
|
How to create exception event listener for a specific controller action, to redirect to another action using its origina
Tag : php , By : chintown
Date : March 29 2020, 07:55 AM
I wish did fix the issue. An EventListener is the most appropriated to change the comportment of your app when an exception is thrown. Use something like : <?php
namespace AppBundle\EventListener;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\Routing\RouterInterface;
use Doctrine\ORM\NoResultException;
class ExceptionResponseListener
{
public function __construct(RouterInterface $router)
{
$this->router = $router;
}
/**
* @param GetResponseForExceptionEvent $event
*/
public function onKernelResponse(GetResponseForExceptionEvent $event)
{
$request = $event->getRequest();
$routeName = $request->get('_route');
$exception = $event->getException();
// Restrict the route by adding a check on the route name
// Or a pattern of route names (!strpos($routeName, '_show'))
// Or for many routes: (!in_array($routeName, ['xxx_show', ...]
// Or the _controller: $request->get('_controller')
// Output something like: "AcmeBundle\\Controller\\DefaultController::showAction"
if ('expected_route_name' !== $routeName) {
return;
}
// Retrieve your param
$params = $request->get('_route_params');
if ($exception instanceof NoResultException) {
// Create a redirection to the edit route
$response = new RedirectResponse(
$this->router->generate('your_edit_route', array('id' => $params['id']))
);
$event->setResponse($response);
}
}
}
services:
# ...
acme.kernel.listener.exception_listener:
class: AppBundle\EventListener\ExceptionResponseListener
tags:
- {name: kernel.event_listener, event: kernel.exception, method: onKernelResponse}
arguments: ['@router']
|
How do I call a method from an action listener without the JFrame freezing and waiting for the action listener to comple
Tag : java , By : Revision17
Date : March 29 2020, 07:55 AM
|