0

我想调用 JavaScript 函数来计算选中的复选框,在这个函数中,我必须调用一个语句来调用控制器的 actionresult 方法,并以活动用户和非活动用户的身份执行某些功能,最后返回 view()

这是我的代码:

if (state == "Dec") {
    alert("Hello..Dear..you are DeActive");
    $.post('@Url.Action("UserDeactive","Admin", new{})' + '?Id=' + strvalue);
}

当我按 F5 运行项目时,此语句在正常项目中运行良好,也使用 VS localhost。

但是当我在 IIS 中托管我的项目时,为了在 LAN 中访问,这不是工作保持 java 脚本调用,但此语句不是调用,也不是导航到操作结果方法..用于执行某些功能..!所以请我......亲爱的......!如果你有任何想法.!

这是我的控制器方法:-

  public ActionResult UserActive(string Id)
    {

        int[] numbers = Id.Split(',').Select(n => int.Parse(n)).ToArray();


        if (numbers != null)
        {
            foreach (int id in numbers)
            {
                User_Master u_master = db.User_Masters.Find(id);
                if (u_master.Is_active == "false")
                {
                    u_master.Is_active = "true";
                    db.Configuration.ValidateOnSaveEnabled = false;
                    db.SaveChanges();

                }

            }

        }

        return RedirectToAction("Dashboard", "Home");

    }
4

1 回答 1

1

使用该$.post()方法的第二个参数,它允许您向服务器发布附加参数:

var url = '@Url.Action("UserDeactive", "Admin")';
$.post(url, { id: strvalue }, function(result) {
    // handle the result of the AJAX call
});
于 2013-02-22T11:53:52.403 回答