Cybercop
Cybercop

Reputation: 8674

on modal's button call controller and Redirect to action

I have a modal.

Html:

<div>
  //this is modal content
</div>

When a button is clicked in modal I call controller's action

JavaScript :

$(function() {
    $("#Yes").click(function () {
        $.get('/myController/myAction/@Model.Id');
    });
});

Here is controller's action

public ActionResult myAction(Guid id)
{
    //do some stuff
    return RedirectToAction("Index");
}

Currently I get forwarded to controller's action but the controller's action RedirectToAction doesn't redirect me to Index action. I stay on same page with modal.

Something I should do? or am not doing right?

Upvotes: 0

Views: 1671

Answers (2)

Nilesh Gajare
Nilesh Gajare

Reputation: 6398

Try this

$(function() {
    $("#Yes").click(function () {
        $.get('/myController/myAction/@Model.Id', function( data ) {
        window.location.href='@Url.Action("myAction","myController")'
     });
});

Upvotes: 1

Deepu--Java
Deepu--Java

Reputation: 3820

Then why are you redirection to index action just give the address of current page

return RedirectToAction("<current page ref>");

Upvotes: 0

Related Questions