【发布时间】:2023-03-30 21:22:01
【问题描述】:
我有一个视图,其中包含一个按钮,单击该按钮必须重定向到控制器中返回另一个视图的方法。问题是这个方法接受参数,我不知道每次点击它正确重定向的按钮时如何传递它们?
方法:
public virtual ActionResult Classificate (int firstArg, int secondArg)
{
//Some logics
return View(MVC.Document.Views.MyView, model: result);
}
html:
<div id="my-button-id">Button</>
并且在视图的 html 中,我希望能够编写一个 js 代码,在每次 "#my-button-id" 单击时使用我传递给函数的 2 个参数重定向到方法在控制器中。
伪解码:
$("#my-button-id").on('click',function(){
redirectToOtherView(4, 5)
});
function redirectToOtherView(fArg, sArg){
//this function to redirect to the Classificate method in the Document controller
//by passing the arguments
}
【问题讨论】:
-
您想使用 ajax 或普通页面刷新/重定向加载视图?
标签: jquery asp.net-mvc asp.net-mvc-routing