Greetings sir,
How can I pass the value of the CategoryId to asp-route-id using the anchor Tag <a>
HomeController
ViewBag.Categories = db.Categories.ToList();
Index View
@Html.DropDownListFor(model => model.CategoryId, new SelectList(ViewBag.Categories, "CategoryId", "CategoryName"), "Select a Category")
To able to use it in another view.
The User will select a particular exam from the Drop down menu which is fetched from the database like this
Public IactionResult index(){
ViewBag.Test = Context.Test.Where(c=>c.IsActive == true).Select(x => new {x.id , x.Name}).Tolist();
Test test = new Test()
Return View(test);
}
This will Populate the Select Exam drop-down List in my Index with C# and Java from my database
@model Test
@Html.Label("Select Exam")
@Html.Dropdownlistfor(m=>m.TestId, new SelectList (ViewBag.Test, "Id", "Name"), "Select Exam")
<a asp-action = "ExamInstruction" asp-route-id ="@Model.Id">Next </a>
I want to use the Id of the the selected Exam to fetch the other exam details into the ExamInstruction View like Time allowed, Total Question.
This is where am struck what am trying with where statement is not working, The querystring returns 0 like this
Home/ExamInstruction/0
Public IactionResult ExamInstruction (Test test){
var Result = Context.Test.Where(e=>e.Id == test.Id).ToList();
ViewBag.TestName = test.Name
ViewBag.TestDuration = test.Duration
}
At this stage, All the viewbag returns null in the ExamInstruction View