asp.net-mvc - 如何通过锚标签调用带有任何 MVC5 控制器参数的索引视图?
问题描述
我有一个 Mvc 控制器
public class ApplicationsController : Controller
{
// GET: Applicants/Applications
public ActionResult Index(Guid? ApplicationId)
{
//some work with the ApplicationId
return View("Application Details");
}
}
在我的另一个 HTML 页面中有一个锚标记,我想通过它调用这个控制器的默认视图(索引视图)。网址应为:
http://localhost:66666/Applicants/Applications/xxxxxxxxxxxxxxxxxxxxxxxxx
我正在尝试通过锚标签调用它:
<script id="applicationDetailstemplate" type="text/x-jsrender">
<a href="../../../Applicants/Applications/{{:id}})">{{:position}}</a>
</script>
网址正确,但从未调用该操作。如果我从锚标记中删除 id,控制器视图会被调用,但 ApplicationId 为空。我怎样才能传递 id 呢?
解决方案
我怀疑,除非您更改了默认路由规则,否则您需要将其编写为
../../../Applicants/Applications?ApplicationId={{:id}}
通常,只有当您的操作方法签名中的变量实际上只是“id”(不是任何其他名称)时,您将 ID 放入路径(而不是查询字符串)的形式才有效。
此外,如果这是视图的一部分,请考虑使用 HTML 帮助程序以确保始终为路径的主要部分生成正确的 URL,例如:
@Url.Action("Applicants", "Applications")?ApplicationId={{:id}}
推荐阅读
- node.js - 理解中的问题“WebSocketServer”不是一个类
- python - 寻找模块/库来设计我的 Tkinter GUI
- python - Pyglet 大精灵故障
- python-3.x - 将数据从 reactjs 发送到 django restful api 时,post menthod 不起作用
- python - Flask-admin如何在行旁边添加按钮
- c++ - 找不到以下 Boost 库: boost_system
- node.js - 登录用户作为未注册用户获得另一个导航
- angular - 带有 Bootstrap 动态选项卡导航的 Angular 应用程序
- html - 使用 Asp .Net WebApi 在 AngularJS 上将数组从服务器绑定到 html 部分时出错
- java - 错误消息:无法确定有效的 Java 主页