P粉4623289042023-09-02 09:30:18
This may not work because your ActionResult List expects a list of strings. In my experience, a list of strings usually requires you to loop through Model -> item.semester to list all the values in the view.
You can try changing List<string>
to a single string
.
public ActionResult List(string classCode = null, string className = null, string semester = null)
Then append this to the "a" tag. Let's say you populate a Viewbag.semesterId
in your controller.
asp-semester="@ViewBag.semesterId"
P粉7544734682023-09-02 09:25:41
You can try to convert List to query string. operate:
public IActionResult A() { ViewBag.List = new List<string> { "a", "b", "c" }; return View(); }
A.cshtml:
@{ var list=ViewBag.List as List<string>; var result = "?semester=" +String.Join("&semester=", list); } <a class="nav-link text-dark" href="/Class/List@(result)">Classes</a>
result: