当我必须将此语句写入Javascript以调用ID为
的Controller Actionresult方法时 function submitForm(state)
{
if (state != "")
{
alert("Hellooo");
var ele = document.getElementById('gridform').elements;
var strvalue = "";
for (var i = 0; i < ele.length; i++)
{
if (ele[i].type == "checkbox")
{
if (ele[i].name == "chkactive[]")
{
if (ele[i].checked == true)
{
if (strvalue != "")
strvalue = strvalue + "," + ele[i].value;
else
strvalue = ele[i].value;
}
}
}
}
}
alert("ok fine" + strvalue);
if (strvalue != null)
{
alert("NOT Null");
}
$.post('@Url.Action("Useractive","Admin", new{})' + '?Id=' + strvalue);
但是我无法调用Admin控制器的UserActive方法 调用此语句时我无法获得任何错误,但只是不能将id导入到控制器方法中... 请帮帮我,我做错了什么原因..!
这是我的Controller Action方法: -
public ActionResult Useractive(string Id)
{
int[] numbers = Id.Split(',').Select(n => int.Parse(n)).ToArray();
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("Userlist","Admin");
}
答案 0 :(得分:0)
尝试修复.post方法:
$.post("@Url.Action(MVC.Admin.UserActive())", { Id: strvalue) }, function(data) {
//Do Something.
});