James Wilson
James Wilson

Reputation: 5150

jQuery to pass to MVC asp.net c# controller

I changed some things around for an item that was requested. This required me to add a parameter to one of the controller ActionResults.

public ActionResult RejectDocument(int id = 0, string rejectReason)
        {
            IPACS_Version ipacs_version = db.IPACS_Version.Find(id);

            ipacs_version.dateDeleted = System.DateTime.Now;
            ipacs_version.deletedBy = User.Identity.Name.Split("\\".ToCharArray())[1];

            db.SaveChanges();

            return RedirectToAction("Approve");
        }

Also this link needs to be activated from jQuery after some jQuery items finish. How do I pass this link off now?

should it be href= Document/RejectDocument?id=222&rejectReason=this is my reject reason

could I then do window.location = href; and it would call the controller and pass in the correct information?

Upvotes: 0

Views: 66

Answers (1)

Felipe Oriani
Felipe Oriani

Reputation: 38598

You could use the Url helper to create the right url using the table routes rules. For sample:

window.location = '@Url.Action("RejectDocument", "YourController", new { id = 222, rejectReason = "this is my reject reason" })';

Upvotes: 3

Related Questions