单选提交按钮表单和重定向
Radio Submit Button Form and Redirect
我想重定向到另一个页面,但同时能够获取 selected 按钮的详细信息。我正在阅读 onsubmit works with HTML and radio buttons 的工作原理。在添加按钮之前,我有一个按钮,只要单击它,它就会将我重定向到下一页。我仍然想做同样的事情,只是能够将单选按钮添加到视图并提交该单选按钮,这样我就可以从 selected.
的按钮中获取信息
我尝试过:
@{
ViewData["Title"] = "Index";
}
<h2>Customer</h2>
<form method="POST">
<input type="radio" value="1" /><label>Valid</label>
<input type="radio" value="2" /><label>Wrong</label>
<input type="radio" value="3" /><label>InValid</label>
<a href="@("window.location.href='" + @Url.Action("SecIndex", "Second") + "'");">
<input type="submit" value="Address Validation" />
</a>
但是,这不会将我重定向到我需要它重定向到的页面。我还注意到,一旦我 select 按钮我就无法取消 select,这是单选按钮功能的一部分吗?
HTML 没有商店功能。没有编程语言就无法获取数据。但是您可以单击重定向到另一个页面。
使用按钮标签并在按钮中使用锚标签,而不是 -
I also noticed that once I select buttons I cannot unselect, is that apart of the radio button feature
是的。这就是它的工作原理。
I still want to do the same thing, just being able to add radio buttons to the view and submit that radio button so that way I can
grab the information from the button that was selected.
如果你想post选择的值到后端,你可以为单选按钮设置name
。因为模型绑定系统会按名称绑定值。
查看:
<form method="POST" asp-action="SecIndex" asp-controller="Second">
<input type="radio" value="1" name="Status"/><label>Valid</label>
<input type="radio" value="2" name="Status"/><label>Wrong</label>
<input type="radio" value="3" name="Status"/><label>InValid</label>
<input type="submit" value="Address Validation" />
</form>
控制器:
public class SecondController : Controller
{
[HttpPost]
public IActionResult SecIndex(string Status)
// you can get "1" or "2" or "3" which based on your checked radio button
{
return RedirectToAction("Privacy");
}
}
我想重定向到另一个页面,但同时能够获取 selected 按钮的详细信息。我正在阅读 onsubmit works with HTML and radio buttons 的工作原理。在添加按钮之前,我有一个按钮,只要单击它,它就会将我重定向到下一页。我仍然想做同样的事情,只是能够将单选按钮添加到视图并提交该单选按钮,这样我就可以从 selected.
的按钮中获取信息我尝试过:
@{
ViewData["Title"] = "Index";
}
<h2>Customer</h2>
<form method="POST">
<input type="radio" value="1" /><label>Valid</label>
<input type="radio" value="2" /><label>Wrong</label>
<input type="radio" value="3" /><label>InValid</label>
<a href="@("window.location.href='" + @Url.Action("SecIndex", "Second") + "'");">
<input type="submit" value="Address Validation" />
</a>
但是,这不会将我重定向到我需要它重定向到的页面。我还注意到,一旦我 select 按钮我就无法取消 select,这是单选按钮功能的一部分吗?
HTML 没有商店功能。没有编程语言就无法获取数据。但是您可以单击重定向到另一个页面。 使用按钮标签并在按钮中使用锚标签,而不是 -
I also noticed that once I select buttons I cannot unselect, is that apart of the radio button feature
是的。这就是它的工作原理。
I still want to do the same thing, just being able to add radio buttons to the view and submit that radio button so that way I can grab the information from the button that was selected.
如果你想post选择的值到后端,你可以为单选按钮设置name
。因为模型绑定系统会按名称绑定值。
查看:
<form method="POST" asp-action="SecIndex" asp-controller="Second">
<input type="radio" value="1" name="Status"/><label>Valid</label>
<input type="radio" value="2" name="Status"/><label>Wrong</label>
<input type="radio" value="3" name="Status"/><label>InValid</label>
<input type="submit" value="Address Validation" />
</form>
控制器:
public class SecondController : Controller
{
[HttpPost]
public IActionResult SecIndex(string Status)
// you can get "1" or "2" or "3" which based on your checked radio button
{
return RedirectToAction("Privacy");
}
}