我試圖用下面的代碼發佈單選按鈕的值。如何在.NET中發佈Radiobutton
@using (Html.BeginForm("RdButton", "Search", FormMethod.Post))
{
<span style="white-space:nowrap;">
<input type="radio" id="HomeShow" name="HomeShow" value="AssemblyDrawings" checked/> Assembly Drawings
<input type="radio" id="HomeShow" name="HomeShow" value="RelatedLiterature"/> Related Literature
<input type="radio" id="HomeShow" name="HomeShow" value="StockParts"> List of stock parts
</span>
}
隨着後期基本形式
[HttpPost]
public ActionResult RdButton(string HomeShow = "")
{
string rdValue = HomeShow;
return View(rdValue);
}
我將如何引用HTML中的價值?在此先感謝
編輯: 更改表格到
@using (Html.BeginForm("RdButton", "Search", FormMethod.Post))
{
<span style="white-space:nowrap;">
@Html.RadioButtonFor(x => x.Show, "Assembly")
@Html.RadioButtonFor(x => x.Show, "Literature")
@Html.RadioButtonFor(x => x.Show, "Parts")
</span>
}
// would this work???
string rdobtn = String.Format("{0}", Request.Form["RdButton"]);
if (rdobtn == "")
{
@Html.Partial("_gotopage");
}
你需要添加你的表單內提交按鈕 – Stormhashe
我可以當單選按鈕更改時提交表單? – Niescier19
當然,但你需要JavaScript來自動提交它,如果這就是你要找的。嘗試搜索「用javascript提交表單」 – Stormhashe