jQuery传递给MVC asp.net c#控制器

本文关键字:net 控制器 asp MVC jQuery | 更新日期: 2023-09-27 18:30:53

我为请求的项目更改了一些内容。 这要求我向其中一个控制器操作结果添加一个参数。

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");
        }

此外,在某些jQuery项目完成后,需要从jQuery激活此链接。 我现在如何传递此链接?

应该是href= Document/RejectDocument?id=222&rejectReason=this is my reject reason

然后我可以做window.location = href;,它会调用控制器并传入正确的信息吗?

jQuery传递给MVC asp.net c#控制器

您可以使用

Url帮助程序通过表路由规则创建正确的 URL。对于示例:

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