我一直在开发一个 MVC4 C# 项目,在我的 Razor View 中,需要在单击到期按钮时将两个参数发送到特定的 MVC 操作,我决定使用 jQuery 来发送这两个参数。
这是点击事件中的代码:
$('#salir').click(function () {
window.location.href = '@Url.Action(actionName: "MostarOrdenInicioEmpleados", controllerName: "Home", new { id = Convert.ToString(Model.num_doc), grupo= Convert.ToInt32(Model.grupo)})';
});
这是我需要发送两个参数的 Controller :
[HttpGet]
[Authorize]
public ActionResult MostarOrdenInicioEmpleados(string id, Int32 grupo)
但是这是 Razor View 中的错误:
错误文本:
Named argument specifications must appear after all fixed arguments have been specified
您能告诉我问题是什么吗?
最佳答案
您使用了两个命名参数(actionName:
和 controllerName:
在您使用固定参数(即未命名的,特别是定位)参数(在本例中,它是以 new
开头的参数,您没有命名),而错误表明您只能将命名参数放在固定的参数之后的。
所以要么
a) 更改参数的顺序,使指定的参数位于最后
b) 命名所有参数,或
c) 不要命名任何参数并确保它们按预期顺序排列。
关于jquery - 如何使用 Url.Action 帮助器通过 jQuery 将两个参数发送到 MVC Action,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50612160/