现在已经解决了,让其他人找到
我试图找到这个问题的答案,虽然我对此很新,我本可以在面前盯着我。所以我道歉。
我创建了一个MVC网络应用程序,它基本上将单选按钮上的选项保存到cookie,然后在下一页显示选择。我想我很接近,但你能不能看看下面的代码,看看为什么我不能让它显示单选按钮文字?提前谢谢!
这是我的控制者;
printf("\f");
网页视图;
public IActionResult WriteCookies(string submitOption, bool isPersistent)
{
if (isPersistent)
{
CookieOptions options = new CookieOptions();
options.Expires = DateTime.Now.AddDays(14);
Response.Cookies.Append("setting", submitOption, options);
}
else
{
Response.Cookies.Append("setting", submitOption);
}
ViewBag.Message = "Turn Registered!";
return View("Meoryou");
}
public IActionResult ReadCookies()
{
var cookieVal = Request.Cookies["setting"];
ViewBag.submitOption = cookieVal;
return View("MeoryouViewReturn");
}
Webview Return;
<div class="cookieCreator">
<form asp-action="WriteCookies" asp-controller="Meoryou">
<input type="radio" value="Sam" name="submitOption"> Sam<br />
<input type="radio" value="Chris" name="submitOption"> Chris<br />
<input type="radio" value="Other" name="submitOption"> Other<br />
<input type="checkbox" name="isPersistent" value="true" /> Save for 14days?<br />
<div style="color: black;">
<input type="submit" name="submitOption" value="Write Cookie" />
</div><br />
</form>
<h4>@ViewBag.Message</h4>
<h4>
<a class="btn-lg" asp-action="ReadCookies" asp-controller="Meoryou">
See whose turn it is.<br />
</a>
</h4>