【发布时间】:2021-02-04 08:09:21
【问题描述】:
在我的 Visual Studio 2019 ASP.NET Core 5.0 MVC 项目中,我希望使用一个公开可用的 Joke API 在information about a Joke API 这是一个try out form for a joke api。 现在我被困在此表单顶部的类别/类别的实现中,我想要实现的功能如下:
案例 1: In the image for category/categories the state of radio and checkboxes are shown
在这里,如果您启用自定义单选按钮和两个复选框(对应于此单选,例如由它控制的 Programming 和 Misc,如图所示 然后请求 URL 变成如下图所示:(忽略 UI 中的所有其他过滤器) Custom radio enabled with Programming and Misc check boxes checked
案例 2: Here the Any radio button is clicked 取消单击自定义单选按钮并禁用其所有复选框,生成的请求 URL 如下所示 Request URL
到目前为止,我对 getrequestURL 操作方法的看法是:
@model WebAPIConsume.ViewModels.JokeRequestURLVM
<form method="post" enctype="multipart/form-data" asp-action="GetRequestURL" asp-controller="Jokes">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="category" class="control-label"> Select category/categories</label>
@*<input type="radio" value="Any" /> Any
<input type="radio" value="Custom" name="Custom" /> Custom:*@
<div><input type="radio" name="category" value="Any" class="control-label" checked="checked" /> Any</div>
<div>
<input type="radio" name="category" value="Custom" class="control-label" /> Custom:
<input type="checkbox" name="customcategory" value="Programming" class="control-label" /> Programming
<input type="checkbox" name="customcategory" value="Misc" class="control-label" /> Misc
<input type="checkbox" name="customcategory" value="Dark" class="control-label" /> Dark
<input type="checkbox" name="customcategory" value="Pun" class="control-label" /> Pun
<input type="checkbox" name="customcategory" value="Spooky" class="control-label" /> Spooky
<input type="checkbox" name="customcategory" value="Christmas" class="control-label" /> Christmas
</div>
</form>
JokesController code:
[HttpGet]
public IActionResult GetRequestURL()
{
return View();
}
View Model:
public class JokeRequestURLVM
{
public string category { get; set; }
public string language { get; set; }
public string format { get; set; }
public Joke joke { get; set; }
public Flags flags { get; set; }
public int amount { get; set; }
}
Models:
Joke:
public class Joke
{
public string type { get; set; }
public string joke { get; set; }
public string setup { get; set; }
public string delivery { get; set; }
public int id { get; set; }
public Flags flags { get; set; }
}
public class Flags
{
public bool nsfw { get; set; }
public bool religious { get; set; }
public bool political { get; set; }
public bool racist { get; set; }
public bool sexist { get; set; }
}
最后,在实现了问题描述中的目标之后,我如何使用选中的单选按钮 (Any) 或 (Custom) 单选按钮的值及其选中的复选框组,例如 Programming 和 Misc,以便请求的结果字符串如下所示: Request URL
我希望将此请求 URI 作为字符串传递给 Jokes Controller 中的 GetRequestURL() 操作方法
【问题讨论】:
标签: c# asp.net-mvc api asp.net-core webapi