我试图在单击按钮时向函数发送参数。但是,我收到以下错误:
app/views/index.scala.html:44:84: not found: value postid [error]
index.scala.html:
<section class="search-sec">
<div class="container">
<form action="window.location.href='@routes.AppController.retrieveByFields(postid, text_filter)';" method="get" novalidate="novalidate">
<div class="row">
<div class="col-lg-12">
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-12 p-0">
<input type="text" id="postid" name = "postid" class="form-control search-slt" placeholder="Enter Post Id" required>
</div>
<div class="col-lg-3 col-md-3 col-sm-12 p-0">
<input type="text" id= "text_filter" name="text_filter" class="form-control search-slt" placeholder="Enter text to search">
</div>
<div class="col-lg-3 col-md-3 col-sm-12 p-0">
<input type="submit" button type="button" class="btn btn-danger wrn-btn">Search</button>
</div>
</div>
</div>
</div>
</form>
</div>
</section>
路线
GET /comments/:id controllers.AppController.retrieveByFields(id: Int, text: java.util.Optional[String])
Controller 功能
public Result retrieveByFields(int postid, java.util.Optional<String> text) throws IOException, ParseException
我做错了什么? 感谢您的帮助。
最佳答案
在您的 View 文件中,它不知道您的 postid
是什么。两件事:
- 您是否在 Controller 中定义了表单值?
- 您是否已将它们传递给您的观点?
关于java - 单击按钮时向 Controller 发送参数 - Java Play,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57124178/