I'm trying to call a controller method on a button click. I created a java function for this, and now I'm stuck...
我试图在按钮点击时调用控制器方法。我为此创建了一个java函数,现在我被卡住了......
using (Html.BeginForm("Create", "Packaging", FormMethod.Post))
{%>
......
<input type="submit" value="Save" id="btnSave" onclick="return btnSave_onclick()" />
}%>
function btnSave_onclick() {
window.open(Url.Action("Index","Packaging"));
}
Thanks in advance.
提前致谢。
2 个解决方案
#1
1
Try this
尝试这个
window.location.href = "@Url.Action("Index", "Packaging")" + "/";
#2
0
It looks like you are trying to redirect the user to the Index action of the Packaging controller once details have been created.
看起来您尝试在创建详细信息后将用户重定向到Packaging控制器的Index操作。
You do this on the server side inside the Create action on the Packaging controller by return the following:
您可以在Packaging控制器上的Create操作内的服务器端执行此操作,返回以下内容:
return RedirectToAction("Index");
#1
1
Try this
尝试这个
window.location.href = "@Url.Action("Index", "Packaging")" + "/";
#2
0
It looks like you are trying to redirect the user to the Index action of the Packaging controller once details have been created.
看起来您尝试在创建详细信息后将用户重定向到Packaging控制器的Index操作。
You do this on the server side inside the Create action on the Packaging controller by return the following:
您可以在Packaging控制器上的Create操作内的服务器端执行此操作,返回以下内容:
return RedirectToAction("Index");