Hello everyone! I hope this video has helped solve your questions and issues. This video is shared because a solution has been found for the question/problem. I create videos for questions that have solutions. If you have any other issues, feel free to reach out to me on Instagram: / ky.emrah
Below, you can find the text related to the question/problem. In the video, the question will be presented first, followed by the answers. If the video moves too fast, feel free to pause and review the answers. If you need more detailed information, you can find the necessary sources and links at the bottom of this description. I hope this video has been helpful, and even if it doesn't directly solve your problem, it will guide you to the source of the solution. I'd appreciate it if you like the video and subscribe to my channel!Pass the selected value of a dropdown in to a URL.Action so that a modal form is displayed on a button click
I want to run up a modal form from a button click. The modal form will be depend on what is selected in the dropdown.
my code is -
div class="row"
div class="col-md-4 mb-2"
select id="AssessmentSelectionId" class="form-select no-progress" asp-for="@Model.AssessmentTypeId" asp-items="@(new SelectList(Model.AssessmentTypeList, "AssessmentTypeId", "AssessmentType"))"
option value="" Please select Assessment Type /option
/select
/div
div class="col-md-4 mb-2"
button id="btnSaveAssessment" type="button" class="btn btn-primary float-right"
data-toggle="ajax-modal" data-target="#english data-url="@Url.Action("Create", "Assessments", new { assessmentType = *Pass the selected id*, assessmentId = 0})" Insert Assessment /button
/div
/div
div class="row"
div class="col-md-4 mb-2"
select id="AssessmentSelectionId" class="form-select no-progress" asp-for="@Model.AssessmentTypeId" asp-items="@(new SelectList(Model.AssessmentTypeList, "AssessmentTypeId", "AssessmentType"))"
option value="" Please select Assessment Type /option
/select
/div
div class="col-md-4 mb-2"
button id="btnSaveAssessment" type="button" class="btn btn-primary float-right"
data-toggle="ajax-modal" data-target="#english data-url="@Url.Action("Create", "Assessments", new { assessmentType = *Pass the selected id*, assessmentId = 0})" Insert Assessment /button
/div
/div
The code controller -
[HttpGet]
public IActionResult Create(int? assessmentType, int? assessmentId)
{
var modelData = new AssessmentsViewModel();
if (assessmentType == 4)
{
return PartialView("_IPDEModalAssessment", modelData);
}
else
{
return PartialView("_GeneralModalAssessment", modelData);
}
}
[HttpGet]
public IActionResult Create(int? assessmentType, int? assessmentId)
{
var modelData = new AssessmentsViewModel();
if (assessmentType == 4)
{
return PartialView("_IPDEModalAssessment", modelData);
}
else
{
return PartialView("_GeneralModalAssessment", modelData);
}
}
So I basically want to pass $('#AssessmentSelectionId').val() as the assessmentType in the url.action. it doesn't like that Jquery if I type that in the action string.
Any help would be greatly appreciated.
[UPDATE]
Tried ajax call, see code below -
$(function () {
$("#btnSaveAssessment").click(function () {
var assessemntTypeId = $('#english
$.ajax({
type: 'GET',
url: '@Url.Action("Create", "Assessments")',
data: { assessmentType: assessemntTypeId, assessmentId: 0 },
success: function (data) {
},
error: function (xhr, status, error) {
console.error('Error fetching wards:', error);
}
});
});
});
$(function () {
$("#btnSaveAssessment").click(function () {
var assessemntTypeId = $('#english
$.ajax({
type: 'GET',
url: '@Url.Action("Create", "AssesSource of the question:
https://stackoverflow.com/questions/7...
Question and source license information:
https://meta.stackexchange.com/help/l...
https://stackoverflow.com/
Информация по комментариям в разработке