<form asp-controller="Application" asp-action="ApplicationSummary" method="post"> 但request为空取不到值
时间: 2023-12-05 10:36:55 浏览: 33
这个问题可能是由于表单中的asp-controller和asp-action属性没有正确设置导致的。请确保这两个属性的值与你的控制器和操作方法名称匹配。此外,还需要确保在表单中使用了正确的HTTP方法(POST或GET)。
如果你已经检查了这些方面,但仍然无法获取请求中的值,那么可能是由于模型绑定问题。你可以尝试在操作方法中添加一个参数,该参数应该与表单中的输入名称匹配,以确保模型绑定正确。
相关问题
<form id="login-form" action="#" method="post">这么改为登录跳转
要将表单提交到一个实际的服务器地址,可以将 `action` 属性设置为目标 URL。例如,如果您想将表单提交到名为 `login.php` 的服务器端脚本,可以将 `action` 属性设置为 `login.php`。如果您希望用户在提交表单后被重定向到另一个页面,可以在服务器端处理表单数据并使用 `header` 函数将用户重定向到另一个页面。下面是一个示例表单代码,将表单提交到 `login.php` 并将用户重定向到 `dashboard.php`:
```
<form id="login-form" action="login.php" method="post">
<!-- 表单输入字段 -->
<input type="text" name="username">
<input type="password" name="password">
<button type="submit">登录</button>
</form>
```
然后,在 `login.php` 中处理表单数据并将用户重定向到 `dashboard.php`,可以使用以下代码:
```php
<?php
// 处理登录逻辑
$username = $_POST['username'];
$password = $_POST['password'];
// ...
// 登录成功后重定向到仪表盘页面
header('Location: dashboard.php');
exit;
?>
```
<form th:action="@{/login}" method="POST">
As an AI language model, I cannot access the context of your application and provide a context-specific answer.
However, I can explain the purpose of the HTML code snippet you shared.
This HTML code snippet creates a form element that has an action attribute set to "/login" and a method attribute set to "POST". When the user submits the form, the data will be sent to the "/login" URL using the HTTP POST method.
The th: prefix in the action attribute suggests that this code is using the Thymeleaf template engine, which allows for dynamic rendering of HTML templates in Spring Framework applications. Depending on the context, the "@" symbol followed by "/login" may be a Thymeleaf expression that evaluates to the actual URL for the login page.